Autor Tema: duvida sobre conversor de 16bits  (Leído 2214 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado rodrigowra

  • PIC10
  • *
  • Mensajes: 10
duvida sobre conversor de 16bits
« en: 07 de Mayo de 2010, 23:44:18 »
hola
estou precisando utilizar um conversor de 16 bit, peguei o mcp3425 cuja saida é a interface I2C,fiz o circuito no proteus onde a saida I2C do mcp vai para a i2c do pic18f4850,fiz o codigo abaixo,mas quando inicio o simulação não ocorre nehuma conversão,o programa fica travado na linha q contem (data = i2c_read();)do codigo abaixo
#include<18f4580.h>
//#device ADC=10
#use delay(clock=4000000)
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#include <lcd.c>
#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3)

main ()
{
char cmd[20];
long int data;
lcd_init();
printf(lcd_putc,"i2c iniciada");
while(1){
i2c_start();
i2c_write(0xD0);
delay_us(10);
data = i2c_read();
printf(lcd_putc,"dado convertido");
sprintf(cmd,"%lu",data);
printf(lcd_putc,":");
printf(lcd_putc,cmd);
}
}
nao sei se esta faltando um comando para o mcp de configuração(ja tentei alguns comandos de escrita,mas nao deu certo),pois o conversor nao responde de modo algum,alguem tem alguma ideia do que pode estar acontecendo?

Desconectado bmfranky

  • PIC16
  • ***
  • Mensajes: 165
    • La Tienda De Fran
Re: duvida sobre conversor de 16bits
« Respuesta #1 en: 10 de Mayo de 2010, 04:36:23 »
Lee-te otra vez el datasheet, no estas inicializando ni leyendo bien, tienes que enviar 2 bytes y leer 3 en 16 bits mode.

Citar
5.3.2 WRITING A CONFIGURATION BYTE
TO THE DEVICE
When the Master sends an address byte with the R/W
bit low (R/W = 0), the MCP3425 expects one
configuration byte following the address. Any byte sent
after this second byte will be ignored. The user can
change the operating mode of the device by writing the
configuration register bits.
If the device receives a write command with a new
configuration setting, the device immediately begins a
new conversion and updates the conversion data.

5.3.3 READING DATA FROM THE DEVICE
When the Master sends a read command (R/W = 1),
the MCP3425 outputs the conversion data bytes and
configuration byte. Each byte consists of 8 bits with
one acknowledge (ACK) bit. The ACK bit after the
address byte is issued by the MCP3425 and the ACK
bits after each conversion data bytes are issued by the
Master.
When the device receives a read command, it outputs
two data bytes followed by a configuration register. In
16 bit-conversion mode, the MSB (= sign bit) of the first
data byte is D15. In 14-bit conversion mode, the first
two bits in the first data byte are repeated MSB bits and
can be ignored, and the 3rd bit (D13) is the MSB (=sign
bit) of the conversion data. In 12-bit conversion mode,
the first four bits are repeated MSB bits and can be
ignored. The 5th bit (D11) of the byte represents the
MSB (= sign bit) of the conversion data. Table 5-3
summarizes the conversion data output of each
conversion mode.
The configuration byte follows the output data bytes.
The device repeatedly outputs the configuration byte
only if the Master sends clocks repeatedly after the
data bytes.
The device terminates the current outputs when it
receives a Not-Acknowledge (NAK), a repeated start or
a stop bit at any time during the output bit stream. It is
not required to read the configuration byte. However,
the Master may read the configuration byte to check
the RDY bit condition.The Master may continuously
send clock (SCL) to repeatedly read the configuration
byte (to check the RDY bit status).
Figure 5-3 shows the timing diagrams of the reading.
Visiten La Tienda De Fran ;-) Aqui. y mi nueva Web Aqui.

Desconectado rodrigowra

  • PIC10
  • *
  • Mensajes: 10
Re: duvida sobre conversor de 16bits
« Respuesta #2 en: 10 de Mayo de 2010, 20:15:38 »
Lee-te otra vez el datasheet, no estas inicializando ni leyendo bien, tienes que enviar 2 bytes y leer 3 en 16 bits mode.

Citar
5.3.2 WRITING A CONFIGURATION BYTE
TO THE DEVICE
When the Master sends an address byte with the R/W
bit low (R/W = 0), the MCP3425 expects one
configuration byte following the address. Any byte sent
after this second byte will be ignored. The user can
change the operating mode of the device by writing the
configuration register bits.
If the device receives a write command with a new
configuration setting, the device immediately begins a
new conversion and updates the conversion data.

5.3.3 READING DATA FROM THE DEVICE
When the Master sends a read command (R/W = 1),
the MCP3425 outputs the conversion data bytes and
configuration byte. Each byte consists of 8 bits with
one acknowledge (ACK) bit. The ACK bit after the
address byte is issued by the MCP3425 and the ACK
bits after each conversion data bytes are issued by the
Master.
When the device receives a read command, it outputs
two data bytes followed by a configuration register. In
16 bit-conversion mode, the MSB (= sign bit) of the first
data byte is D15. In 14-bit conversion mode, the first
two bits in the first data byte are repeated MSB bits and
can be ignored, and the 3rd bit (D13) is the MSB (=sign
bit) of the conversion data. In 12-bit conversion mode,
the first four bits are repeated MSB bits and can be
ignored. The 5th bit (D11) of the byte represents the
MSB (= sign bit) of the conversion data. Table 5-3
summarizes the conversion data output of each
conversion mode.
The configuration byte follows the output data bytes.
The device repeatedly outputs the configuration byte
only if the Master sends clocks repeatedly after the
data bytes.
The device terminates the current outputs when it
receives a Not-Acknowledge (NAK), a repeated start or
a stop bit at any time during the output bit stream. It is
not required to read the configuration byte. However,
the Master may read the configuration byte to check
the RDY bit condition.The Master may continuously
send clock (SCL) to repeatedly read the configuration
byte (to check the RDY bit status).
Figure 5-3 shows the timing diagrams of the reading.

consegui resolver o problema,o problema era mesmo os dois primeiros bytes  enviados


 

anything