I have question regarding selecting channel from multiplexer. I'm trying to receive some temperature reading from the two sensors which shared the same address and while I'm using one sensor, it can work perfectly. However, when I tried to fix the second sensor onto the circuit and edit the program abit, it doesn't work. Can someone assist me?
here's the code when it starts to read:
void readSensor(void) {
int ch;
TWI_init_master();
for (ch=0; ch<2; ch++)
{
TWI_start();
TWI_write_address(0xE0); // set multiplixer
TWI_write_data(0); // disable all ch
TWI_write_data(ch+1); // enable ch-ch+1
TWI_stop();
delay100us(1);
TWI_start();
TWI_write_address(0x14);// writing to sensor
TWI_write_data(0x4C);// asking for data
delay100us(1);
TWI_repeated_start();// restart
TWI_read_address(0x15);// read
if (ch==0)
{
for(i = 0; i < 34; i++) {
TWI_read_data();//geting data
readbuff[i] = recv_data;
}
if(!(D6T_checkPEC(readbuff, 34))) {
writeChar(0x50, USB);
writeChar(0x50, USB);
writeChar(0x50, USB);
}
else
{
for(i = 2; i < 34; i++)
{
temp = readbuff[i];
writeChar(temp, USB);
delay100us(1);
}
}
}
else if (ch==1)
{
for(i = 0; i < 34; i++) {
TWI_read_data();//geting data
readbuff2[i] = recv_data;
}
if(!(D6T_checkPEC(readbuff2, 34))) {
writeChar(0x50, USB);
writeChar(0x50, USB);
writeChar(0x50, USB);
}
else
{
for(i = 2; i < 34; i++)
{
temp = readbuff2[i]; //readbuff 2 is defined for sensor 2, its just another array
writeChar(temp, USB); // Send data to the real term
delay100us(1);
// delay10ms(10);
}
}
}
TWI_stop();
delay100us(10);
// delay10ms(10);
//TWI_repeated_start();// restart
//TWI_stop();
}
//TWI_stop(); }
Thanks!