hssn601
Junior Member level 2
- Joined
- Apr 26, 2011
- Messages
- 24
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Activity points
- 1,420
Hi All,
i have developed a code to read temperature but its not working please help to correct it.
Sensor Model:am2315
Sensor info:
i have developed a code to read temperature but its not working please help to correct it.
Sensor Model:am2315
Sensor info:
Code:
#include <18f4525.h>
#include <stdlib.h>
#fuses INTRC_IO, NOWDT, PUT , BROWNOUT, NOLVP, NOPROTECT, NOMCLR
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use i2c(master, sda=PIN_C4, scl=PIN_C3, FORCE_HW)
unsigned char rx_byte,rx_byte1,rx_byte2,rx_byte3;
void main(void)
{
SET_TRIS_A(0x00);
int a=0;
while (a<2){
output_high(PIN_A1);
delay_ms(500);
output_low(PIN_A1);
delay_ms(100);
a++;
}
while (1)
{
printf ("Start i2c \n");
i2c_start();
delay_ms(50);
i2c_write(0xB8); /* Device Address */
i2c_write(0x03);
// reading humidity
rx_byte = i2c_read(0x00);
rx_byte1 = i2c_read(0x01);
//read temp
rx_byte2 = i2c_read(0x02);
rx_byte3 = i2c_read(0x03);
printf ("rx_byte1 = 0x%2.2X\r 0x%2.2X\r \n", rx_byte, rx_byte1);
printf ("rx_byte1 = 0x%2.2X\r 0x%2.2X\r \n", rx_byte2, rx_byte3);
i2c_stop();
printf ("End\n");
}
}
Attachments
Last edited: