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/TMS320F28027: TMS320F28027-C2000 launchpad

Part Number: TMS320F28027


Tool/software: Code Composer Studio

Hi guys, so I've been suffering from the I2C module of the TMS320F28027. I've been through a lot of existing code, mine looks the same but still does not work. I've put a breakpoint in the interrupt , and I use a USB/I2C module to send commands to my C2000 launchpad but still nothing works. Any help would be very appreciated thank you very much .

Code : 

/**
* main.c
*/
#include "DSP28x_Project.h"
#include "f2802x_common/include/clk.h" // Header for Clock
#include "f2802x_common/include/gpio.h" // Header for GPIO
#include "f2802x_common/include/pll.h" // Header for PLL
#include "f2802x_common/include/wdog.h" // Header for Watchdog
#include "f2802x_common/include/i2c.h" // Header for Watchdog
#include "f2802x_headers/include/F2802x_PieVect.h" // Header for PIE
#include "f2802x_headers/include/F2802x_I2c.h"
#include "f2802x_common/include/F2802x_I2c_defines.h"
#include "myI2C.h"


void ioInit();
GPIO_Handle myGpio;
__interrupt void i2c_int1a_isr(void);
void I2CA_Init();

volatile Uint16 I2CSTR_snapshot1;
volatile Uint16 I2CSTR_snapshot2;
volatile Uint16 I2CSTR_snapshot3;

void main()
{

// #ifdef _FLASH
// memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
// #endif

InitSysCtrl();

initI2CGpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
InitPieCtrl();

IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.I2CINT1A = &i2c_int1a_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
I2CA_Init();
PieCtrlRegs.PIEIER8.bit.INTx1 = 1;

// [???] Enable CPU INT8 which is connected to PIE group 8 (I2C)
IER |= M_INT8;

// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM

while(1) //This will run indefinitely
{
DELAY_US(1000000);
}

}

#define ALT_B_SDA 0x00000001
#define ALT_B_SCL 0x00000004
#define GPAMUX1_CFG 0X00000000
#define GPAMUX2_CFG 0X00000000
#define GPBMUX1_CFG (ALT_B_SDA + ALT_B_SCL)
#define AIOMUX1_CFG (0x00003330) // AIO10-12-14 are AIO, others are default disabled
// The direction register has no effect on pins configured as peripheral functions.
#define GPIOA_DIR 0x00000000 //
#define GPIOB_DIR 0x00000000 //
#define AIO_DIR 0x00005400 // MUX_ADDR2-0 as GPIO outputs only
#define GPIOB_QSEL1 0xF000000F // Asynch input GPIO32 (SDA) and GPIO33 (SCL)
void initI2CGpio(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all = 0x0000; // GPIO functionality GPIO0-GPIO15
GpioCtrlRegs.GPAMUX2.all = 0x0000; // GPIO functionality GPIO16-GPIO31
GpioCtrlRegs.GPBMUX1.all = 0x0000; // GPIO functionality GPIO32-GPIO34

GpioCtrlRegs.AIOMUX1.all = 0x0000;

GpioCtrlRegs.GPADIR.all = 0x0000; // GPIO0-GPIO31 are GP inputs
GpioCtrlRegs.GPBDIR.all = 0x0000; // GPIO32-GPIO34 are inputs
GpioCtrlRegs.AIODIR.all = 0x0000; // AIO2,4,6,19,12,14 are digital inputs
//
GpioCtrlRegs.GPAQSEL1.all = 0x0000; // GPIO0-GPIO15 Synch to SYSCLKOUT
GpioCtrlRegs.GPAQSEL2.all = 0x0000; // GPIO16-GPIO31 Synch to SYSCLKOUT
GpioCtrlRegs.GPBQSEL1.all = 0x0000; // GPIO32-GPIO34 Synch to SYSCLKOUT

//
// Pull-ups can be enabled or disabled
//
GpioCtrlRegs.GPAPUD.all = 0x0000; // Pullup's enabled GPIO0-GPIO31
GpioCtrlRegs.GPBPUD.all = 0x0000; // Pullup's enabled GPIO32-GPIO34
EDIS;
}
int myxdy = 20;
void I2CA_Init()
{
I2caRegs.I2COAR = 0x60; // Own address
I2caRegs.I2CPSC.all = 5; // Prescaler - need 7-12 Mhz on module clk (F2809: 9)
I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
I2caRegs.I2CCNT = 1; // Get 1 byte
I2caRegs.I2CIER.all = 0x18; // Clear interrupts (was 0)
I2caRegs.I2CSTR.bit.RRDY = 1; // Clear flag

I2caRegs.I2CIER.bit.RRDY = 1; // Receive data ready interrupt
I2caRegs.I2CIER.bit.AAS = 0; // [2011-05-13, PP, v2.50] Addressed as slave now disabled
I2caRegs.I2CIER.bit.XRDY = 1; // Transmit data ready interrupt
I2caRegs.I2CIER.bit.SCD = 1; // Stop condition detection

I2caRegs.I2CMDR.all = 0x08A0; // Take I2C out of reset
// Stop I2C when suspended
// A VOOOOOOOOOOOOOOOIR****************************
// I2caRegs.rsvd1 &= ~0x1; // [2018-04-26] Clear the BCM bit (otherwise causes a bug in I2C communication)
I2caRegs.I2CEMDR.bit.BCM =0;
I2caRegs.I2CMDR.bit.FREE = 1;
// Enable interrupts required for this example
// Enable I2C interrupt 1 in the PIE: Group 8 interrupt 1
//PieCtrlRegs.PIEIER8.bit.INTx1 = 1;
I2caRegs.I2CFFRX.all = 0x2040; // Enable RXFIFO, clear RXFFINT,
// [2011-05-10, PP, v2.??] Very important when using the new i2c_isr
RxIndex = 0;
TxIndex = 0;

return;
}


uint16_t myabc = 10;
__interrupt void
i2c_int1a_isr(void) // I2C-A
{
char Flush;
Flush = I2caRegs.I2CDRR;
myabc =myabc+2;
uint16_t IntSource;
IntSource = I2caRegs.I2CSTR.all;

// Read interrupt source
//IntSource = I2caRegs.I2CISRC.bit.INTCODE & 0x7;

//I2CSTR_snapshot2 = I2caRegs.I2CSTR.all;

switch(IntSource)
{
case I2C_NO_ISRC: // =0
{
break;
}

case I2C_ARB_ISRC: // =1
{
break;
}

case I2C_NACK_ISRC: // =2
{
break;
}

case I2C_ARDY_ISRC: // =3
{
I2caRegs.I2CSTR.bit.ARDY = 0;
break;
}

case I2C_AAS_ISRC: // =7
{
break;
}

case I2C_RX_ISRC: // =4
{
break;
}


case I2C_TX_ISRC: // =5
{
break;
}

case I2C_SCD_ISRC: // =6
{
break;
}

default:
asm(" ESTOP0"); // Halt on invalid number.
}

I2CSTR_snapshot3 = I2caRegs.I2CSTR.all;

// Enable further I2C (PIE Group 8) interrupts by acknowledging this one.
PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;

}

  • Amine,

    Please spell out the problem you are facing. It will be difficult for us to look through your code to guess your problem.

    1) Does I2C interrupt not fire when expected?
    2) Did you probe for I2C signals? If so, did you observe I2C signals?
    3) Is your I2C bus always busy?
    4) Are you not receiving ACK signals from slave device?
    5) Are you trying to use I2C as slave receiver?

    These were my observations looking into your code:-
    a) I2C GPIOs are not configured right? You can't expect to observe anything on I2C bus unless you configure GPIOs right.

    Regards,
    Manoj
  • Hi, thank for your reply.
    1) Does I2C interrupt not fire when expected?
    No the interrupt never fires actually
    2) Did you probe for I2C signals? If so, did you observe I2C signals?
    Yes I did, everything looks fine, the slave ( my C2000) just never answers back
    3) Is your I2C bus always busy?
    No, everything is fine with the bus
    4) Are you not receiving ACK signals from slave device?
    No, I did not receive any ACK :(
    5) Are you trying to use I2C as slave receiver?
    Sorry, yes I'm using my C2000 TMS320F28027 as a slave.


    - I corrected the GPIO's, here a the new :
    EALLOW;
    // Configure each GPIO pin (general purpose IO or function)
    GpioCtrlRegs.GPAMUX1.all = 0X00000000; // GPIO0 - GPIO15
    GpioCtrlRegs.GPAMUX2.all = 0X00000000; // GPIO16 - GPIO31
    GpioCtrlRegs.GPBMUX1.all = (ALT_B_SDA + ALT_B_SCL); // #define ALT_B_SDA 0x00000001 & #define ALT_B_SCL 0x00000004

    // Configure each AIO pin (AIO or ADC function)
    GpioCtrlRegs.AIOMUX1.all = (0x00003330); // AIO functionality
    //
    // Direction
    GpioCtrlRegs.GPADIR.all = 0x00000000; // GPIO0 - GPIO31 direction
    GpioCtrlRegs.GPBDIR.all = 0x00000000; // GPIO32 - GPIO38 direction
    GpioCtrlRegs.AIODIR.all = 0x00005400; // AIO direction
    GpioCtrlRegs.GPBQSEL1.all = GPIOB_QSEL1; // GPIO32 - GPIO38 Synch to SYSCLKOUT
    GpioCtrlRegs.GPAPUD.all = 0xF000000F; // PULL-UP on port A
    GpioCtrlRegs.GPBPUD.all = 0x00000000; // PULL-UP on port B
    EDIS;


    - But still nothing works... Thank you for your help
  • Amine,

    From GPIO configuration perspective, these are the things to check:-

    For example, if you trying to configure GPIO32, GPIO33 as I2C pins here are the steps you need to take. Please check if the GPIO configurations are correct with your code.

    1) Enable pull-ups on I2C GPIO pins

    GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;
    GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0;

    2) Configure GPIO pins as ASYNC GPIO Input Qualification

    GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 0;
    GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 0;

    3) Configure I2C pins

    GpioCtrlRegs.GPBMUX1.GPIO32 = 1;
    GpioCtrlRegs.GPBMUX1.GPIO33 = 1;

    When you are using I2C as slave, you need to configure "Adddressed as slave condition (AAS)" interrupt.

    Regards,
    Manoj
  • Thank you again for your answer.
    So I put the GPIO configuration that you gave me and set the (AAS) bit to 1 but still nothing, the interrupt never triggers...
  • Can you check whether I2CSTR.AAS bit is set? If this bit is not set, then it then I2C module didn't realize that it is being addressed as slave.

    Make sure your I2C master is sending the right slave address on I2C bus.

    Regards,
    Manoj
  • Yes this bit is set.
    I'm sure that my master sends to the right address, I defined it to 0x60 in I2caRegs.I2COAR = 0x60; // Own address
    And that's what I wrote to my master.
    Still nothing... Interrupt never triggers..
    I tried to use a second board just to be sure this is not a hardware problem and still nothing..
  • How are you connecting two board together? Did you make sure to short ground pins on two boards?

    -Manoj
  • There are both connected via USB to my PC which means they have the same supply.

    Amine

  • Amine,

    I'm not 100% whether that would help. I use a wire to short the grounds together anyway.

    Regards,
    Manoj
  • I haven't heard back from you in a while. Is this issue resolved? Can I close this thread?