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.

EK-TM4C123GXL: I2C Slave Initialization

Part Number: EK-TM4C123GXL

I'm trying to configure my TM4C as a slave to use with a Raspberry Pi 3 master for I2C. I'm using direct register access instead of TivaWare. I can't find any documentation on this. I used the following code but it isn't writing to the I2C registers in the debugger. I tried writing to the SCSR register to enable it as a slave but it remains 0. Is there something I am missing in initialization? 

// I2C0SCL connected to PB2
// I2C0SDA connected to PB3

void I2C_Slave_Init(void){
   SYSCTL_RCGCI2C_R |= 0x0001; // activate I2C0
   SYSCTL_RCGCGPIO_R |= 0x0002; // activate port B
   while((SYSCTL_PRGPIO_R&0x0002) == 0){};// ready?

   GPIO_PORTB_AFSEL_R |= 0x0C; // 3) enable alt funct on PB2,3
   GPIO_PORTB_ODR_R |= 0x08; // 4) enable open drain on PB3 only
   GPIO_PORTB_DEN_R |= 0x0C; // 5) enable digital I/O on PB2,3

// 6) configure PB2,3 as I2C
   GPIO_PORTB_PCTL_R = (GPIO_PORTB_PCTL_R&0xFFFF00FF)+0x00003300;
   GPIO_PORTB_AMSEL_R &= ~0x0C; // 7) disable analog functionality on PB2,3

   I2C0_SCSR_R |= 0x01; // enable slave
   I2C0_SOAR_R = (I2C0_SOAR_R & ~0x7F)| 0x3C; // 9) slave address

}

  • Dear Jessica,
    You will find that feedback on this forum is way faster if you use Tivaware. May I suggest you to do such? TI encourages developers to avoid using Direct Registry.
    If you simply include i2c.h on your project and use the functions explained on chapter 16 of the Tivaware Driverlib User Guide, you shall be able to achieve your goals quickly.
    Regards
    Bruno
  • Hello Bruno

    Thanks for the support on downgrading DRM and pointing to the use of TivaWare....
  • Hi Amit and Bruno,

    Although I understand why you are suggesting the use of TivaWare, I would prefer to use DRM because I like programming at a lower level of abstraction and knowing what is going on in the device. Even so, I have tried using TivaWare for this project and ran into issues. It seems that there's only decent documentation for setting up the TM4C123 as a master. I've looked at i2c.h and other examples in TivaWare, including slave_receive_int.c, and they all initialize the master. I want to set up my TM4C123 as a slave to be used with a Raspberry Pi 3 and when trying to use this code, it is not recognized by the other device. I have read through the Tivaware Driverlib User Guide and the TM4C123 data sheet several times and am still having trouble.

    But like I said, for this project I would like to use Direct Registry. The datasheet is not very clear on what needs to be set up when using the TM4C123 as a slave and for some reason the bits are not being set when I try writing to the registers.

    Thanks,
    Jessica
  • Hello Jessica,

    Our support with DRM is minimal (and of course we can assist you in transitioning to TivaWare). The SCSR is a WO register when setting the control. When Read is performed the register returns the status which is not the same as the write path characteristics for Control mode.