Good afternoon.
I am trying to figure out how to make a PIC16F877A to read the temperature from the DS1620 sensor. Accordingly to the datasheet of the DS1620, I need to send two nibbles A (AAh) to the sensor and may it return the bytes with the temperature. This is what I've tried until now.
However, since in the datasheet isnt specified the protocol (only says 3-wire communication), I am trying some bit-banging, with no success.
This is the code of what I've tried until now:
#define DQ RC0_bit
#define CLK RC1_bit
#define RST RC2_bit
unsigned int resp;
int rcv;
void clock() {
CLK = ~CLK;
Delay_ms(10);
}
int readSensor() {
int cont = 0;
RST = 0x00;
CLK = 0;
Delay_ms(30);
resp = 0;
while (cont <= 16) {
clock();
resp |= DQ;
resp = resp<<1;
clock();
cont++;
}
RST = 0x01;
Delay_ms(30);
return resp;
}
void writeSensor(char ch) {
int cont = 0;
RST = 0x00;
CLK = 0;
Delay_ms(30);
resp = 0;
while (cont <= 16) {
DQ = ch & 0b00000001;
clock();
ch = ch>>1;
clock();
cont++;
}
RST = 0x01;
Delay_ms(30);
RST = 0x00;
Delay_ms(30);
RST = 0x01;
Delay_ms(30);
}
void main() {
UART1_Init(9600); // Initialize UART module at 9600 bps
UART1_Write_Text("Start"); UART1_Write(10); UART1_Write(13);
TRISC = 0b00000000;
PORTC = 0b00000100;
writeSensor(0xAA);
Delay_ms(30);
rcv = readSensor();
Delay_ms(100); // Wait for UART module to stabilize
UART1_Write(rcv);
}
Here are the circuit in Proteus:
I am new in bit banging and PIC, but I have some experience with C language.
May you say (or do some approach) what am I missing in order to read the temperature of this thermometer?