Jump to content
43oh

msp430g2553 (launchpad) USCI i2c slave


Recommended Posts

I've been banging my head against the wall trying to get even the most basic USCI I2C slave examples working with the g2553. I'm using a Bus Pirate (which acts as a i2c master) at 100Khz to send bytes to the g2553 (slave). I'm using an untouched example from slac485a (Examples for MSP430g2xx3) -- msp430g2xx3_uscib0_i2c_09.c .. Here it is below (since it's fairly short):

 

//******************************************************************************
// MSP430G2xx3 Demo - USCI_B0 I2C Slave RX multiple bytes from MSP430 Master
//
// Description: This demo connects two MSP430's via the I2C bus. The master
// transmits to the slave. This is the slave code. The interrupt driven
// data receiption is demonstrated using the USCIB0 RX interrupt.
// ACLK = n/a, MCLK = SMCLK = default DCO = ~1.2MHz
//
//							 /|\ /|\
//			 MSP430G2xx3	 10k 10k	 MSP430G2xx3
//				 slave		 | |	 master
//			 ----------------- | | -----------------
//		 -|XIN P3.1/UCB0SDA|<-|---+->|P3.1/UCB0SDA XIN|-
//		 |				 | |	 |				 |
//		 -|XOUT			 | |	 |			 XOUT|-
//		 |	 P3.2/UCB0SCL|<-+----->|P3.2/UCB0SCL	 |
//		 |				 |		 |				 |
//
// D. Dang
// Texas Instruments Inc.
// February 2011
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
#include "msp430g2553.h"
unsigned char *PRxData;					 // Pointer to RX data
unsigned char RXByteCtr;
volatile unsigned char RxBuffer[128];	 // Allocate 128 byte of RAM
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;				 // Stop WDT
P1SEL |= BIT6 + BIT7;					 // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7;					 // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST;					 // Enable SW reset
UCB0CTL0 = UCMODE_3 + UCSYNC;			 // I2C Slave, synchronous mode
UCB0I2COA = 0x48;						 // Own Address is 048h
UCB0CTL1 &= ~UCSWRST;					 // Clear SW reset, resume operation
UCB0I2CIE |= UCSTPIE + UCSTTIE;		 // Enable STT and STP interrupt
IE2 |= UCB0RXIE;						 // Enable RX interrupt
while (1)
{
PRxData = (unsigned char *)RxBuffer; // Start of RX buffer
RXByteCtr = 0;						 // Clear RX byte count
__bis_SR_register(CPUOFF + GIE);	 // Enter LPM0 w/ interrupts
									 // Remain in LPM0 until master
									 // finishes TX
__no_operation();					 // Set breakpoint >>here<< and read
}										 // read out the RxData buffer
}
//------------------------------------------------------------------------------
// The USCI_B0 data ISR is used to move received data from the I2C master
// to the MSP430 memory.
//------------------------------------------------------------------------------
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
*PRxData++ = UCB0RXBUF;				 // Move RX data to address PRxData
RXByteCtr++;							 // Increment RX byte count
}
//------------------------------------------------------------------------------
// The USCI_B0 state ISR is used to wake up the CPU from LPM0 in order to
// process the received data in the main program. LPM0 is only exit in case
// of a (re-)start or stop condition when actual data was received.
//------------------------------------------------------------------------------
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCIAB0RX_ISR(void)
{
UCB0STAT &= ~(UCSTPIFG + UCSTTIFG);	 // Clear interrupt flags
if (RXByteCtr)						 // Check RX byte counter
__bic_SR_register_on_exit(CPUOFF);	 // Exit LPM0 if data was
}										 // received

 

The MSP430 successfully interrupts on start conditions, but sending any data does not trigger the USCIAB0TX interrupt and it appears the MSP430 holds SDA low (presumably because UCB0RXBUF is not being read, since the interrupt is not being triggered). I've tripled checked my pinouts (1.6 and 1.7, even tried swapping them at the suggestion of google, but no luck). I've removed the jumper on Pin 1.6. I'm using 10k pull up resistors that are working. I've read the user guide, datasheet, and countless websites, but I just can't seem to figure this out. Am I doing something stupid or is this example code just plain wrong?

Link to post
Share on other sites

Are you using a 7bit or 8bit address?

The slave address is listed as 0x48, or 0b1001000. The 8 bit version would be 0x90, and 0x91 for reading.

Ti's example would expect a 7bit address + w bit, so the bus pirate should be sending (Start, 0x90, [your data byte], Stop).

Link to post
Share on other sites

Thanks for the suggestion cde -- I am using 0x90 and 0x91. The other interesting thing is that when I use the Bus Pirate's built in I2C address scan, it finds 0x90 and 0x91 and then every other address after those numbers (which don't exist) -- see below:

 

 

Searching I2C address space. Found devices at:

0x90(0x48 W) 0x91(0x48 R) 0x92(0x49 W) 0x93(0x49 R) 0x94(0x4A W) 0x95(0x4A R) 0x96(0x4B W) 0x97(0x4B R) 0x98(0x4C W) 0x99(0x4C R) 0x9A(0x4D W) 0x9B(0x4D R) 0x9C(0x4E W) 0x9D(0x4E R) 0x9E(0x4F W) 0x9F(0x4F R) 0xA0(0x50 W) 0xA1(0x50 R) 0xA2(0x51 W) 0xA3(0x51 R) 0xA4(0x52 W) 0xA5(0x52 R) 0xA6(0x53 W) 0xA7(0x53 R) 0xA8(0x54 W) 0xA9(0x54 R) 0xAA(0x55 W) 0xAB(0x55 R) 0xAC(0x56 W) 0xAD(0x56 R) 0xAE(0x57 W) 0xAF(0x57 R) 0xB0(0x58 W) 0xB1(0x58 R) 0xB2(0x59 W) 0xB3(0x59 R) 0xB4(0x5A W) 0xB5(0x5A R) 0xB6(0x5B W) 0xB7(0x5B R) 0xB8(0x5C W) 0xB9(0x5C R) 0xBA(0x5D W) 0xBB(0x5D R) 0xBC(0x5E W) 0xBD(0x5E R) 0xBE(0x5F W) 0xBF(0x5F R) 0xC0(0x60 W) 0xC1(0x60 R) 0xC2(0x61 W) 0xC3(0x61 R) 0xC4(0x62 W) 0xC5(0x62 R) 0xC6(0x63 W) 0xC7(0x63 R) 0xC8(0x64 W) 0xC9(0x64 R) 0xCA(0x65 W) 0xCB(0x65 R) 0xCC(0x66 W) 0xCD(0x66 R) 0xCE(0x67 W) 0xCF(0x67 R) 0xD0(0x68 W) 0xD1(0x68 R) 0xD2(0x69 W) 0xD3(0x69 R) 0xD4(0x6A W) 0xD5(0x6A R) 0xD6(0x6B W) 0xD7(0x6B R) 0xD8(0x6C W) 0xD9(0x6C R) 0xDA(0x6D W) 0xDB(0x6D R) 0xDC(0x6E W) 0xDD(0x6E R) 0xDE(0x6F W) 0xDF(0x6F R) 0xE0(0x70 W) 0xE1(0x70 R) 0xE2(0x71 W) 0xE3(0x71 R) 0xE4(0x72 W) 0xE5(0x72 R) 0xE6(0x73 W) 0xE7(0x73 R) 0xE8(0x74 W) 0xE9(0x74 R) 0xEA(0x75 W) 0xEB(0x75 R) 0xEC(0x76 W) 0xED(0x76 R) 0xEE(0x77 W) 0xEF(0x77 R) 0xF0(0x78 W) 0xF1(0x78 R) 0xF2(0x79 W) 0xF3(0x79 R) 0xF4(0x7A W) 0xF5(0x7A R) 0xF6(0x7B W) 0xF7(0x7B R) 0xF8(0x7C W) 0xF9(0x7C R) 0xFA(0x7D W) 0xFB(0x7D R) 0xFC(0x7E W) 0xFD(0x7E R) 0xFE(0x7F W) 0xFF(0x7F R)

 

So this suggests to me that the MSP430 isn't doing its cleanup properly.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...