otavio_fisica
Newbie level 1
ds1621
Hi, I have built a system to read temperature using the DS1621 and the PIC16F819. This PIC reads the temperature from the DS1621 through I2C and sends the data to the computer through RS-232. I am using the following code for tests (PIN_B1 and PIN_B4 are the ones used for the I2C communication):
I'm using PCM 3.235 version.
#include <16F819.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A3,rcv=PIN_A4,bits=8,stream=TEMP)
#use i2c(Master,sda=PIN_B1,scl=PIN_B4, force_HW)
while(true)
{
fprintf(TEMP,"Iniciando medida... \n\r");
output_high(PIN_B1);
output_high(PIN_B4);
i2c_start();
i2c_write(0x90);
i2c_write(0xac);
i2c_write(3);
i2c_stop();
delay_ms(20);
i2c_start();
i2c_write(0x90);
i2c_write(0xee);
i2c_stop();
delay_ms(800);
i2c_start();
i2c_write(0x90);
i2c_write(0xaa);
i2c_start();
i2c_write(0x91);
data1=i2c_read();
data2=i2c_read(0);
i2c_stop();
fprintf(TEMP,"Temperatura: %c - %d\n\r", data1, data2);
}
This is not the final code. I've built it just to test the communication. I have two problems. The first one is with the RS-232 communication. I use the MAX232N for this purpose. When the PIC is not tied to the VCC, it sends the data to the computer perfectly! (CRAZY...) But when I put the PIC tied to the VCC, then it starts sending parts of what it should send in time intervals that do not correspond to those of the code. Again, when I turn the VCC off (for the PIC) it sends the information perfectly, in the correct time instants. This is one problem... the second one is that it returns (when the PIC is not tied to the VCC) the information: "Temperatura: - -1". That is, data1 does not return any value and data 2 returns "-1". I am going crazy with this. I have already used the same schematic for the RS-232 and I2C communication with other PIC and other slave and it worked fine.
Does someone have any suggestion of what could be happening.
Any information would be of great value.
Hi, I have built a system to read temperature using the DS1621 and the PIC16F819. This PIC reads the temperature from the DS1621 through I2C and sends the data to the computer through RS-232. I am using the following code for tests (PIN_B1 and PIN_B4 are the ones used for the I2C communication):
I'm using PCM 3.235 version.
#include <16F819.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A3,rcv=PIN_A4,bits=8,stream=TEMP)
#use i2c(Master,sda=PIN_B1,scl=PIN_B4, force_HW)
while(true)
{
fprintf(TEMP,"Iniciando medida... \n\r");
output_high(PIN_B1);
output_high(PIN_B4);
i2c_start();
i2c_write(0x90);
i2c_write(0xac);
i2c_write(3);
i2c_stop();
delay_ms(20);
i2c_start();
i2c_write(0x90);
i2c_write(0xee);
i2c_stop();
delay_ms(800);
i2c_start();
i2c_write(0x90);
i2c_write(0xaa);
i2c_start();
i2c_write(0x91);
data1=i2c_read();
data2=i2c_read(0);
i2c_stop();
fprintf(TEMP,"Temperatura: %c - %d\n\r", data1, data2);
}
This is not the final code. I've built it just to test the communication. I have two problems. The first one is with the RS-232 communication. I use the MAX232N for this purpose. When the PIC is not tied to the VCC, it sends the data to the computer perfectly! (CRAZY...) But when I put the PIC tied to the VCC, then it starts sending parts of what it should send in time intervals that do not correspond to those of the code. Again, when I turn the VCC off (for the PIC) it sends the information perfectly, in the correct time instants. This is one problem... the second one is that it returns (when the PIC is not tied to the VCC) the information: "Temperatura: - -1". That is, data1 does not return any value and data 2 returns "-1". I am going crazy with this. I have already used the same schematic for the RS-232 and I2C communication with other PIC and other slave and it worked fine.
Does someone have any suggestion of what could be happening.
Any information would be of great value.