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.

I2C INTERFACING USING MSP430G2553

Other Parts Discussed in Thread: PCF8574, MSP430G2553, PCF8574A

HI all,

am trying to interface MSP430G2553 controller with pcf8574 I/O expander IC.but am not getting the o/p.My attempt was to send a particular bit pattern from MSP controller to the PCF8574 and show the bit pattern on the LEDs connected to the 8 port pins

#include "msp430g2553.h"
void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop Watchdog Timer
  // Set up a 16MHz main clock
  DCOCTL = CALDCO_16MHZ;
  BCSCTL1 = CALBC1_16MHZ;
  P1SEL |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
  P1SEL2|= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
  UCB0CTL1 |= UCSWRST;                      // Enable SW reset
  UCB0CTL0 = UCMST+UCMODE_3+UCSYNC;         // I2C Master, synchronous mode
  UCB0CTL1 = UCSSEL_2+UCSWRST;              // Use SMCLK, keep SW reset
  UCB0BR0 = 160;                             // fSCL = SMCLK/12 = ~100kHz
  UCB0BR1 = 0;
  UCB0I2CSA = 0x40;                         // Set slave address
  UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
  IE2 |= UCB0TXIE;                          // Enable TX interrupt
  while (1)
{
  UCB0CTL1 |= UCTR + UCTXSTT;               // I2C TX, start condition
 //__bis_SR_register(CPUOFF + GIE);           // CPU off, interrupts
  //while (UCB0CTL1 & UCTXSTT);               // Loop until I2C STT is sent
  //UCB0CTL1 |= UCTXSTP;                        // I2C stop condition after 1st TX
}
}
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
 //static unsigned char data=0x0A;
 UCB0TXBUF = 0xAA;
}

  • nibin thomas said:
    UCB0I2CSA = 0x40;                         // Set slave address


    The 8574s slave address is n't 0x40, it is 0x20 to 0x27. The 8th bit which is included into the 'address' in the PCF datasheet, is added by the USCI based on the UCTR bit when sending the address.

    The users guide tells that it has to be a 7 bit address, right-justified, but most I2C slave datasheets list it as a left-justified value padded with the R/W bit. So this is a typical misunderstanding.

    p.s.: on the PCF8574A, the address is 0x38 to 0x3f

    If you look at the Fig.11 on page 10 of this datashheet, you'll see what I mean.

  • P1SEL |= BIT6 + BIT7;   
      P1SEL2|= BIT6 + BIT7;

    im new to msp430g2553 programming  .so can u explain briefly the above statement and whats the pin function selection operation on both registers.

  • The two statements switch P1.6 and P1.7 pin to tertiery operation (which is hardware USCI module in this case). The default is software-controlled GPIO (except for P2.6/P2.7 on this MSP)

    The exact mapping of PxSELy register configuration and resulting port pin functions is in the device datasheet (chapter: port schematics, in a table below each pin's schematic)

  • Dear Members,

    I'm trying to run the code above with no success.

    I have a Launchpad rev 1.5 with g2553. P1.6 jumper is removed,

    I have the PCF8574N plugged to a breadboard. SDA and SCL are pulled up with 10K resistors to VCC.
    The address bits are on GND, so I guess I have 0x20 address on the bus.
    I have plugged 8 LEDs to the PCF ports anf GND without resistors. VCC comes from the Launchpad, so it should be 3.3V.

    The problem is I can't see any result, LEDs don't turn on.
    Of course I debugged the code, but I could not reveal any problem... You know I'm totally new to the microcontroller world, and have limited experience in C...

    I guess PCF8574 and 8574N are the same, right?
    Do You have any Idea what am I doing wrong?

    Thanks!

  • Fairlane said:
    I guess PCF8574 and 8574N are the same, right?

    Logically, yes. 'N' is a variant in PDIP-16 package. Other packages (SOIC-16, TSSOP-20 VQFN-16/20) have different suffix letters attached.

    However, an 'A' suffix usually marks an improved and technically not 100% identical part (even though these are usually backwards compatible)
    So a PCF8574AN could perhaps have a wider input voltage range or higher output drive capability. The version suffix is usually placed before the package suffix, if present.

**Attention** This is a public forum