Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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!

share|improve this question
    
Could you add the type of sensor you're using and a link to the datasheet? –  PeterJ Mar 12 '14 at 7:41
    
The sensor I'm using is omron D6T. The datasheet is "store.mansteri.com/download/datasheets/d6t_white_paper.pdf"; and "mouser.com/ds/2/307/D6T_datasheet_Nov2012-237760.pdf"; –  user38577 Mar 12 '14 at 9:34
    
You have quotation marks as part of your links, which causes them to fail. Also, please include a schematic of "the circuit" used to connect these sensors. –  Joe Hass Mar 12 '14 at 20:30
    
Did you solve the problem? I am facing the same problem. If you have solved it please share the solution. Thanks –  user40273 Apr 12 '14 at 7:18

2 Answers 2

Yes I have used a multiplexer to connect them. enter image description here

I have used this schematic diagram to guide me through for the second sensor.

The multiplexer which I'm using is stated on the diagram, PCA9548A(8ch). The datasheet: http://www.ti.com/lit/ds/symlink/pca9548a.pdf

share|improve this answer
1  
This should have been an edit to your question rather than posted as an answer. You can go back and edit your question at any time to add additional information. –  PeterJ Mar 15 '14 at 4:07
    
If you want to supply additional information and images, update your original post and add the information there, instead of posting it as an answer. Comments work for this too, although you can't inline images into a comment. –  Nick Alexeev Mar 15 '14 at 4:08

These sensors use an I2C interface and have a hard-coded address. You can't use two of them on the same I2C bus. You will need to create an electrically separate I2C bus for each sensor, with distinct SDA and SCL lines.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.