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.

CCS/LAUNCHXL-F28069M: I2C slave receiver

Part Number: LAUNCHXL-F28069M
Other Parts Discussed in Thread: MOTORWARE

Tool/software: Code Composer Studio

Hello,

I need help with developing c2000>arduino communication via i2c. I've studied threads from this forum but i've found only scraps of information. My goal is to use launchpad as SLAVE receiver to read 4 bytes(string) from arduino, and use that in modified motorware project. I have a few questions.

1)I started by adding includes and this from this topic: Is it all i need to get things working? Or should i make some modifications in hal.c/gpio.c/whateverelse.c?:)

2)I read that other people had to do some hardware modifications, cutting some jumpers to use GPIO32 and GPIO33 pin as i2c bus. Is it nessesary? Why and what to do if so? 

3)What is needed to be done in initialisation? Everything i saw on this topic included clock setting, interrupts, NACK, some InitSysCtrl() function, some InitPieCtrl(); and other refering to this Pie-thing. Do i really need all of these, since my launchpad wont be driving i2c bus, just responding to data coming from it?

I've figured out this setup:

void I2cInit(void) 
  {
  EALLOW;  //?

  GpioCtrlRegs.GPBPUD.bit.GPIO32 = 1;   // Enable pull-up for GPIO32 (SDAA)
  GpioCtrlRegs.GPBPUD.bit.GPIO33 = 1;   // Enable pull-up for GPIO33 (SCLA)
  
  GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3; // Asynch input GPIO32 (SDAA)
  GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 3; // Asynch input GPIO33 (SCLA)
  
  GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1;  //gpio 32 sda
  GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1;  //gpio 33 scl
  
  EDIS;  //?

  I2caRegs.I2CMDR.bit.IRS = 0;          //i2c reset to setup
  I2caRegs.I2COAR = 9;                  //launchpad slave adress
  I2caRegs.I2CPSC.all = 9;              //prescaller 
  
  I2caRegs.I2CMDR.bit.MST= 0;           //slave mode
  I2caRegs.I2CMDR.bit.TRX = 0;          //receive mode
  I2caRegs.I2CMDR.bit.NACKMOD = 0;      
  I2caRegs.I2CMDR.bit.FDF = 0;          
  
  I2caRegs.I2CCNT = 4;                  //4 bytes to receive
  
  I2caRegs.I2CIER.all = 0;              //no interrupts
  
  I2caRegs.I2CMDR.bit.IRS = 1;
  
  return;
  }

What else should i set here?

4)How does the slave-reading procedure/function look? How to spot the write-request from master and how to respond to it?

4a)Since the data register is 16bit i assume i should use FIFO buffer or just making it write to 4byte array will work? Do you have some example on it? Make master request 4 bytes is pretty straight-forward but how does it work when it comes to slave-receiver?

5)Would it be good to do interrupt if data come from the bus and write it in that interrupt? How to achieve that? Won't it spoil all the control code working in motorware project?

Thanks for any help.

Best

  • Hi Marcin,

    1. You'll need to make sure you have all the correct includes and source files to use I2C bit-fields. Then you'll need to configure the GPIOs properly (looks like you've done this part).

    2. You don't need to. I think what you're referencing from a different post was for the F28027 LP, not the F2806x. It was due to contention (I2C and SPI sharing the line I believe)

    Marcin Chojnacki said:
    What is needed to be done in initialisation? Everything i saw on this topic included clock setting, interrupts, NACK, some InitSysCtrl() function, some InitPieCtrl(); and other refering to this Pie-thing. Do i really need all of these, since my launchpad wont be driving i2c bus, just responding to data coming from it?

    3. You'll need to configure the pins for SDA/SCL, configure the internal I2C module clock that the peripheral (I2CPSC register). I believe InitSysCtrl is integrated somewhere within the Motorware code, I2C may need to be enabled within the respective function (could be disabled by default). NACK handling should be implemented by you. You'll likely want to use interrupts to service incoming I2C comms. The PIE is a part of interrupt handling.

    4. There aren't any examples we have available that demonstrate a slave device unfortunately. The write-request from the master can be triggered using the Addressed as Slave interrupt or bits, then you'd read out the data from the I2CDRR register.

    Marcin Chojnacki said:
    Since the data register is 16bit i assume i should use FIFO buffer or just making it write to 4byte array will work?

    You can use FIFO or non-FIFO. Saving each incoming byte to an array will work (Array[] = I2Cregs.I2CDRR), but FIFO may be more efficient.

    5. Interrupts will be best I'd imagine so you don't have to poll the AAS bit. You'll have to implement I2C so it doesn't affect the motor control portions. i.e. make a lower priority interrupt, service the I2C comms with low latency

    I'd suggest playing around with the I2C portion by itself first before adding it to your motorware project.

    Best,

    Kevin