This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

I/O Expander Code Example

Other Parts Discussed in Thread: MSP430F2619

Hi All,

I work with msp430f2619 and i want to have more I/O by using PCA9655 (16 bit I/O Expander).

I tested a program but it didn't work.

Would you mind sending me an "I/O Expander Code Example"?

Best Regards.

  • mrjz rose said:
    I tested a program but it didn't work.

    Which program? What didn't work?

    Why do you want to use an I/O expander? Why don't you use a bigger MSP instead? There are MSPs with up to 83 I/Os. So the effort of programming an expander (slow reaction times, complex handling), the additional cost and also the layout space isn't worth the result.
    Except, of course, you want to add all 8 possible expanders to the I2C-bus (giving you 96I/O).

  • Hi,

    I use msp4302619, which support extended temperature range(-55 to 105 ) and there is no MSP with more i/o greater than 48 whit this spec.

    and i need a program that runs the 16 bit I/O Expander (PCA9655).

    Thanks

  •  Hi, as Jeans wrote to you, what program you tested, what is wrong? So:

    • what you need this program doing
    • what speed is necessary to read write to
    • is pc interrupt capability needed or just polled?
    • how many pc expander do you wish to connect to?
    • how long are communication lines?

    Missing some or all of these specs none can figure out what you need and your question remain unanswered or just receive first guess then ignored.

  • Hi,
    I want to work with 16 bit I/O expander (PCA9655) because i need more i/o
    on msp430f2619. The msp430 and pca9655 are in a small board, and the speed is 400k.

    I attach the complete program and schematic for you. In this program i want to load a sample data on LED's

    and read the switch.

    Thanks.


    #include "msp430x26x.h"
    #include "TI_USCI_I2C_master.h"

    unsigned char timercounter;
    unsigned char config_array[3] = { 0x06, 0x00, 0xff };
    unsigned char output_array[3] = { 0x02, 0x35, 0xff };



    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

      BCSCTL1 = CALBC1_8MHZ;
      DCOCTL = CALDCO_8MHZ;

      _EINT();

      TI_USCI_I2C_transmitinit(0x40,0x12);  // init transmitting with USCI
      while ( TI_USCI_I2C_notready() );         // wait for bus to be free
      if ( TI_USCI_I2C_slave_present(0x40) )    // slave address may differ from
      {                                         // initialization
          
        TI_USCI_I2C_transmitinit(0x40,0x12);  // init transmitting with
        while ( TI_USCI_I2C_notready() );         // wait for bus to be free
        TI_USCI_I2C_transmit(3,config_array);       // start transmitting
        
        while ( TI_USCI_I2C_notready() );         // wait for bus to be free
        TI_USCI_I2C_transmit(3,output_array);       // start transmitting  
                
      }
     
      LPM3;
     
    }

    I2C TEST.rar
  • Hi Robert,
    I want to work with 16 bit I/O expander (PCA9655) because i need more i/o
    on msp430f2619. The msp430 and pca9655 are in a small board, and the speed is 400k.

    I attach the complete program and schematic for you. In this program i want to load a sample data on LED's

    and read the switch.

    Thanks.


    #include "msp430x26x.h"
    #include "TI_USCI_I2C_master.h"

    unsigned char timercounter;
    unsigned char config_array[3] = { 0x06, 0x00, 0xff };
    unsigned char output_array[3] = { 0x02, 0x35, 0xff };



    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

      BCSCTL1 = CALBC1_8MHZ;
      DCOCTL = CALDCO_8MHZ;

      _EINT();

      TI_USCI_I2C_transmitinit(0x40,0x12);  // init transmitting with USCI
      while ( TI_USCI_I2C_notready() );         // wait for bus to be free
      if ( TI_USCI_I2C_slave_present(0x40) )    // slave address may differ from
      {                                         // initialization
          
        TI_USCI_I2C_transmitinit(0x40,0x12);  // init transmitting with
        while ( TI_USCI_I2C_notready() );         // wait for bus to be free
        TI_USCI_I2C_transmit(3,config_array);       // start transmitting
        
        while ( TI_USCI_I2C_notready() );         // wait for bus to be free
        TI_USCI_I2C_transmit(3,output_array);       // start transmitting  
                
      }
     
      LPM3;
     
    }

    I2C TEST.rar
  •  Hi, from schematic base address 0x40 is selected, config thru command 06 set direction of led port to output and button to input, command 2 send to output pattern 0x35 word some led on.

     What happen? is program hang somewhere? are you able to single step program and report if complete execution or not?

  • Hi,

    when i debug the program, the routine "TI_USCI_I2C_transmit(3,config_array);" should transmit 3 byte of config_array,

    but it only runs for one and PCA9655 doesn't configure.

    Best regards

  •  Hi Where you got Library is also slave one available?

     To cure the problem try just modify the 3 lines on master.c then tell me if it is solved, if not try a breakpoint on IRQService and see what value are on the 3 variables.

    signed char byteCtr;
    unsigned char *TI_receive_field;
    unsigned char *TI_transmit_field;
     

    to

    volatile signed char byteCtr;
    volatile unsigned char *TI_receive_field;
    volatile unsigned char *TI_transmit_field;
     

  • mrjz rose said:
    TI_USCI_I2C_transmitinit(0x40,0x12);  // init transmitting with USCI


    Hmmm, isn't 0x12 the clock divider? (I don't see anyhting else that would define the I2C baudrate)
    8MHz/18 is 444.4kHz. You're 11% faster than allowed for even high-speed I2C. You need a divider of 0x14 on 8Mhz. At least.

    However, if the transmit only runs for the first byte, it is possible that the loop gets a NACK from the slave. Or (I don't know the exact code) it even gets a NACK when trying to address the slave (wrong address, or clock too fast). The first byte has to be written to TXBUF before the slave has even answered the addressing, due to the double-buffering and clock-stretching mechanisms. So the 'first loop' you see is actually the preparation, and a transfer never starts.

    Note that some devices have a timeout (even if this doesn't make much sense on I2C in most situations), so if two bytes are too long apart 8due to debug stops of the processor) they may exit the current transmission and may even discard all data received so far (e.g. in case of multibyte commands).

  • Hi

    Thank you so much, I had solved my problem.

    The address of pca9655 in data sheet is 0x40 but you should consider the address 0x20.

    best regards.

  • Hi

    Thank you so much,

    The address of pca9655 in data sheet is 0x40 but you should consider the address 0x20.

    best regards.

  • mrjz rose said:
    The address of pca9655 in data sheet is 0x40 but you should consider the address 0x20.

    The typical wrong addres in I2C device datasheets: The 'address' contains the R/W bit. In your case, it is likely givven as 0x40 for write and 0x41 for read operations. However, teh address is only ht eupper 7 bits and the LSB is NOT part of the device address itself, only part of the start condition address byte. The MSPs USCI therefore differentiates between the 7 address bits (0x20) and the R/W bit (added automatically through the UCTR bit)

**Attention** This is a public forum