CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

TCA9548A
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Blackjackmaster



Joined: 14 May 2023
Posts: 30

View user's profile Send private message

TCA9548A
PostPosted: Mon Jun 19, 2023 1:03 pm     Reply with quote

The only changes are the micro going from Arduino based system to using a PIC16F877A.

I have not looked into the I2C library that is being used for the Arduino code.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Jun 19, 2023 1:07 pm     Reply with quote

The critical big difference between the Arduino, and a PIC is the
voltage that is accepted as a Vih on the I2C bus. The Arduino will
accept anything above 2.4v, the PIC (when running off 5v), needs
4v. This is why the voltage actually being applied to the pull-ups on
the PIC connection is vital.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: TCA9548A
PostPosted: Mon Jun 19, 2023 1:18 pm     Reply with quote

Blackjackmaster wrote:

The only changes are the micro going from Arduino based system to using a PIC16F877A.

You still didn't tell us

1. The number of pull-up resistors you have installed. Do you have 19 ?
2. The value of the resistors.
3. The pull-up voltage on each resistor.
Blackjackmaster



Joined: 14 May 2023
Posts: 30

View user's profile Send private message

TCA9548A
PostPosted: Mon Jun 19, 2023 2:23 pm     Reply with quote

Hello,

There 4.7K Resistors (pullups) from the micro to the TCA and 5V on the SDA and SCL lines.

There 4.7K Resistors (pullups) on the output of SD0/SD1 on the TCA and 5V on the SDA and SCL lines.

The empty (unused) outputs on the TCA do not have resistors on them.

Reset line 10K to VCC

Status bit on TCA:
Stat: 01
ACK addr: E0

Thanks....
temtronic



Joined: 01 Jul 2010
Posts: 9240
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jun 19, 2023 5:06 pm     Reply with quote

add all the other pullups...
while YOU don't use them, having them 'float' could allow stray glitch to enter the device.

do you have bypass cap at the chips ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Jun 19, 2023 11:29 pm     Reply with quote

You talk about all the pull-ups going to 5v.
Yes the ADXL345 is a 3.3v device. It needs to be running off 3.3v, and
have pull-ups to 3.3v.
Blackjackmaster



Joined: 14 May 2023
Posts: 30

View user's profile Send private message

TCA9548A
PostPosted: Tue Jun 20, 2023 7:58 am     Reply with quote

The ADXL345 is a board from Adafruit and VIN is from 3.3V - 5.0V as it says it on the board. Logic is also 3.3V-5.0V

I will pull all the channels up to 5V even though I am not using them.
Blackjackmaster



Joined: 14 May 2023
Posts: 30

View user's profile Send private message

TCA9548A
PostPosted: Tue Jun 20, 2023 9:19 am     Reply with quote

Hello,

I pulled up the unused SDA/SCL ports on the TCA9548A. The channels are not switching. If I connect the ADXL to the PICF16F877A directly I can see the address 0xA6. I know the ADXL is working and the PIC16F877A.
I have changed out the TCA9548A with another one in case I damaged it, and it does the same thing. I put the part back into the Arduino circuit and works fine.

Any other suggestions?
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Tue Jun 20, 2023 9:31 am     Reply with quote

You are probably going to need to use SMBus mode on the 5V PIC so that it can properly read the lower voltage 3.3V I2C of the peripheral.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Wed Jun 21, 2023 12:32 am     Reply with quote

No, the TDA does level translation.

However I pointed out that the Arduino code is not talking to the address
he says the TDA is on. He never answered on this....
The Arduino is addressing it on 0xE0, not on 0xEE, which he claims it is
wired for.
This would mean that A0, A1 & A2 are actually pulled low, not high.
Blackjackmaster



Joined: 14 May 2023
Posts: 30

View user's profile Send private message

TCA9548A
PostPosted: Wed Jun 21, 2023 5:44 am     Reply with quote

A0,A1,A2 are pulled low on the Arduino board and the PIC16F877A board. The response Arduino is 0X70 and the response PIC is 0xE0.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Wed Jun 21, 2023 7:16 am     Reply with quote

So have you changed:

#define TCAaddr 0xEE

Needs to be 0xE0 or the TCA will not be addressed
Blackjackmaster



Joined: 14 May 2023
Posts: 30

View user's profile Send private message

TCA9548A
PostPosted: Wed Jun 21, 2023 8:22 am     Reply with quote

Code:
//#fuses HS
#FUSES NOWDT                    //No Watch Dog Timer
//#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPUT                   //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(crystal=20mHz)
#use rs232(baud=9600,parity=N,UART1,bits=8,stream=RS232,errors)
#use i2c(Master, slow,i2c1,force_hw)

unsigned int8 I2C_Address;
unsigned int8 status;
unsigned int8 Device_Count = 0;
int8 Channel;




#define TCAaddr 0xE0                                         
const int8 bus_array[8]={1,2,4,8,16,32,64,128};

void select_bus(int bus)
{
    if (bus > 7 )
        return;                                                //trap illegal bus numbers
    I2C_start();
    I2C_write(TCAaddr);
    I2C_write(bus_array[bus]);                                 //select specified bus number
    I2C_stop();                                                //I2C bus now routes to BUS number
}

//Then with the ADXL wired as described above, simply call
//    select_bus(0);
//And the ADXL will now be connected to the I2C bus with level
//translation.
//You then write to the ADXL as normal.


int8 get_ack_status(int8 address)
{
   int8 ack;

   i2c_start();
   delay_us(20);
   ack = i2c_write(address);                                   // Status = 0 if got an ACK
   i2c_stop();
   delay_us(20);
   if(ack == 0)
      return(TRUE);
   else
      return(FALSE);
}

void Get_I2C_Addresses(void){
// Try all slave addresses from 0x10 to 0xEF.
// See if we get a response from any slaves
// that may be on the i2c bus.
//   for(I2C_Address = 0x10; I2C_Address < 0xF0; I2C_Address+=2)   // original
   for(I2C_Address = 0x10; I2C_Address < 0xE8; I2C_Address+=2)   // trimmed down to avoid scanning mux address, just in case
      {
       status = get_ack_status(I2C_Address);
       printf("Stat: %X\n\r", status);
       if(status == TRUE)
         {
            printf("ACK addr: %X\n\r", I2C_Address);
            Device_Count++;
            delay_ms(100);
         }
      }
   
   if(Device_Count == 0){
      printf("Nothing Found\n\r");
      delay_cycles(1);
   }
   else{
      printf("Found: %u\n\r", Device_Count);
      delay_cycles(1);
   }
}




//=================================
void main(){
   
   output_float(PIN_B0);
   output_float(PIN_B1);


   for(Channel = 0; Channel < 8; Channel++)
   {                     // loop through channels
     
      select_bus(bus_array[Channel]);
      printf("\n\rTCA Port #%d\n\r",Channel);
     
      Device_Count = 0;
         
      Get_I2C_Addresses();   //I2C scanner
     
   }
   while(1);
}


Output when connected to PIC16F877A
Stat: 01
ACK addr: C0
Stat: 01
ACK addr: C2
Stat: 01
ACK addr: C4
Stat: 01
ACK addr: C6
Stat: 01
ACK addr: C8
Stat: 01
ACK addr: CA
Stat: 01
ACK addr: CC
Stat: 01
ACK addr: CE
Stat: 01
ACK addr: D0
Stat: 01
ACK addr: D2
Stat: 01
ACK addr: D4
Stat: 01
ACK addr: D6
Stat: 01
ACK addr: D8
Stat: 01
ACK addr: DA
Stat: 01
ACK addr: DC

Output when connected to TCA9548 SD0/SC0:
TCA Port #0
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 00
Stat: 01
ACK addr: E0
Stat: 00
Stat: 00
Stat: 00
Found: 1
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Wed Jun 21, 2023 10:33 am     Reply with quote

You are using the select bus function incorrectly. The syntax is:

select_bus(Channel);

You are trying to tell it to select a bus that doesn't exist....
It uses the array internally to select the bus. Doesn't expect to
be called with the array value.... Sad
PrinceNai



Joined: 31 Oct 2016
Posts: 480
Location: Montenegro

View user's profile Send private message

PostPosted: Wed Jun 21, 2023 10:46 am     Reply with quote

That is my mistake then, he used it as I wrote it Embarassed

Very nice catch, I will correct it in the code.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group