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.

FAcing issue with the I2C slave receiver .

Dear All,

Facing problem with the I2C communication between HL Modem and Microcontroller to recieve GPS data, where in which Transmitter is working fine but not able to receive anythig at the receiver interrupt. below is the peice of CODE which is used for Transmitter and Receiver Initialization.

Connection type   : (I2C MASTER) HL 6528 MODEM( Seirra Wireless)   to  (I2C SLAVE) Microcontroller :MSP4305438A

Steps taken care before coding are

1. Pull up resistors are placed at the Master end of the I2C for both SDA and CLOCK

Please do suggest us is there anything wrong with the initialization.

void Master_Init_I2C( void )
{

P10SEL |= 0x06;                                                                 // Assign I2C pins to USCI_B3
UCB3CTL1 |= UCSWRST;                                               // Enable SW reset
UCB3CTL0 = UCMST + UCMODE_3 + UCSYNC;      // I2C Master, synchronous mode
UCB3CTL1 |= UCSSEL_2 + UCTR + UCSWRST;       // Use SMCLK, keep SW reset
UCB3BR0 = 12;                                                                  // fSCL = SMCLK/12 = ~100kHz
UCB3BR1 = 0;
UCB3CTL1 &= ~UCSWRST;                                          // Clear SW reset, resume operation
UCB3I2CSA = 0x48;                                                        // Slave Address is 048h
UCB3IE |= UCNACKIE + UCTXIE;                                // Enable TX interrupt

while (1)
{
_delay_cycles(50);                                             // Delay required between transaction
PTxData = (unsigned char *)TxData;             // TX array start address
TXByteCtr = sizeof TxData;                              // Load TX byte counter

UCB3CTL1 |= UCTXSTT;                                 // I2C TX, start condition
__bis_SR_register(LPM0_bits + GIE);         // Enter LPM0, enable interrupts
__no_operation();                                             // Remain in LPM0 until all data
while (UCB3CTL1 & UCTXSTP);                   // Ensure stop condition got sent // is TX'd

}

}

 

void Slave_Init_I2C( void )
{
P10SEL |= 0x06;                                                       // Assign I2C pins to USCI_B0
UCB3CTL0 &= ~UCMST;
UCB3CTL0 = UCMODE_3 + UCSYNC;              // I2C Slave, synchronous mode
UCB3CTL1 |= UCSWRST;                                    // Enable SW reset
UCB3CTL1 &= ~UCTR;                                        //set up as receiver
UCB3CTL1 &= ~UCSWRST;                              // Clear SW reset, resume operation
UCB3I2COA = 0x48;                                             // Own Address is 048h
UCB3IE |= UCRXIE ;                                            //+ UCSTPIE + UCSTTIE; // Enable STT, STP & RX interrupt


while (1)
{

     PRxData = (unsigned char *)RxBuffer;      // Start of RX buffer
    RXByteCtr = 0; // Clear RX byte count
   __bis_SR_register(LPM0_bits + GIE);        // Enter LPM0, enable interrupts
    // Remain in LPM0 until master
   // finishes TX
    __no_operation();                                         // Set breakpoint >>here<< and read
} // read out the RxData buffer

}

Any Suggetions would be greatly appreciated,  waiting for the responce.

Thank you,

Nithin

  • Hello Nithin,

    What value are the pull-up resistances? Our recommendation is typically 4.7 to 10 kohms. I'm a bit confused by the code given and know very little about the HL6528, are MSP430F5438As being used as both the master and slave? If so you might want to consider trying one of the I2C example pairs found in the MSP430F543xA_Code_Examples package: www.ti.com/.../slac375

    If the F5438A is only used as a slave device there should only be slave code. It is recommended to initialize all USCI registers with UCSWRST = 1, including UCBxCTL0 and UCBxI2COA. Providing the interrupt routines would also be helpful.

    Regards,
    Ryan
  • Some general addition to I2C;

    To handle the I2C protocol there are 4 pieces of software applicable:

    • Master

    - Generate Clock (CLK)

    - Generate START/STOP (S/P)

    - Writes Slave Address

    - Controls Read/Write bit

    • Slave

    - Detecting Own Address

    • Transmitter

    - Writes Data to the Bus

    - Waits for ACK/NACK

    • Receiver

    - Reads Data from the Bus

    - Acknowledge Data reception (ACK)

     

    The Transmitter and Receiver are fully in-depended pieces of software with each their own ISR and are equal for both Master and Slave.

    The Transmitter writes data to a Master or a Slave and waits for an acknowledge (ACK).

    The Receiver reads data from a Master or a Slave and acknowledge the reception (ACK). The Receiver can end the transmission by not-acknowledging (NACK) for example if the Receiver can’t read more data bytes.

    If the Master needs only to read data from the Slave, the Master may have only Receiver and the Slave only Transmitter.

    If the Master needs only to write data to the Slave, the Master may have only Transmitter and the Slave only Receiver.

    Normally the hardware will be initialized as Slave (either Master or Slave) and his Own address will be loaded, in this case there is no specific Slave software needed other then the Receiver and/or Transmitter part.

**Attention** This is a public forum