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.

GPIO on F2803x Devices as Input and Output

Hi

I want to write a Software Driver for I2C using GPIO pins of F2803x. I needed multiple I2Cs to manage slow and fast devices separately and thus avoid delays because a slow device has hogged the bus.

Currently I configured SCL as output. SDA configured with a pullup and configured as output to write data and then changed to input to read ACK.

I use GPxSET and GPxCLEAR command after direction is set.


Just wanted to ask if this is the correct approach. Will this produce any bus conflicts ? etc.

Jawwad

  • Hi,

    Moving your post to right forum to be better answered.

    Thanks & regards,
    Sivaraj K
  • Hi Jawwad,

    Just wanted to confirm, are you trying to emulate I2C using GPIOs ie software implementation of I2C?
    Also, check processors.wiki.ti.com/.../I2C_Tips

    Regards,
    Gautam
  • Thanks Gautam,
    Yes I want to emulate I2C using GPIO pins. I worked the same day, when i posted the Q, a couple of hours bec the project timelines are short.

    Here is my implementation that works for me

    I simply define SCL as output.
    SDA as input with pullup disabled and external pull up. Avoid read modify write instructions and change SDA to input/output as required.


    #define __SDA_ASINPUT EALLOW;GpioCtrlRegs.GPADIR.bit.GPIO19 = 0;EDIS;
    #define __SDA_ASOUTPUT EALLOW;GpioCtrlRegs.GPADIR.bit.GPIO19 = 1;EDIS;

    u_char SWI2CRead(u_char ACK){
    u_char i, Data=0,x;
    __SET_SDA_IO
    __SDA_ASINPUT
    usec(1);
    __CLR_SCL_IO
    usec(1);
    for (i = 0; i < 8; i++) {
    __SET_SCL_IO
    usec(1);
    x = __RD_SDA
    if(x)Data |=1;
    if(i<7)Data<<=1;
    __CLR_SCL_IO
    usec(1);
    }
    if(ACK==I2C_ACK) __CLR_SDA_IO //SDA = 0 to send ACK, 1 for NACK
    else __SET_SDA_IO //Master sends ACK for more data and NACK other wise
    __SDA_ASOUTPUT
    usec(1);
    __SET_SCL_IO
    usec(1);
    __CLR_SCL_IO
    return Data;
    }
  • Just wanted to ask if this is the correct approach. Will this produce any bus conflicts ? etc.

    Being a software implementation of I2C I don't see any conflicts happening. Secondly I've never seen anybody working on the same though I was very much fond of implementing software_uart, spi and i2c with other manufacturer's mcus.
    If the above is really able to replicate the I2C peripheral then the work is really appreciable :)

    Goodluck & Regards,
    Gautam
  • Hi Gautum

    Thanks for the reply. The code works perfectly. I am already communication with EEPROM and RTC on software I2C. The hardware I2C is being used by Gyro, Accelero etc.

    I have posted it here and any one could use and modify it. There is one caution though, the pipeline architecture of DSC may cause timing issues at different clocks and I would recommend use of Logic Analyzer or a dual channel oscilloscope to check for right timings and put nops to ensure things happen in order.

    This is specially true for SPI where at high speed a GPIO Chip select may de-select the device while the transmission is still in progress.

    Good Luck

    Jawwad

  • Excellent and thanks for the tips!

    Regards,
    Gautam
  • Thanks Gautum. Once I have tested it fully, I will post the code here.
    And u are doing a marvelous job on this forum, really amazing. Keep up the good work