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/TMS320F28377S: i2c without interrupt

Part Number: TMS320F28377S
Other Parts Discussed in Thread: CONTROLSUITE

Tool/software: Code Composer Studio

Dear All,

I am working on  TMS320F28377S processor and I am new to this. I am interfacing ee prom AT24C16 with processor. I see the examples available with  control suit which uses interrupt. But I want to develop simple function without using interrupt. This is the function I write to I2C, and they are not working. My previous experience is on ATMEGA controller, so please any one can help for same.

Thank's


 void I2CA_Init(void)
 {

 GPIO_SetupPinMux(32, GPIO_MUX_CPU1, 1);
 GPIO_SetupPinMux(33, GPIO_MUX_CPU1, 1);

 I2caRegs.I2CPSC.all = 6;              // Pre scaler - need 7-12 Mhz on module clk
  I2caRegs.I2CCLKL = 10;                // NOTE: must be non zero
  I2caRegs.I2CCLKH = 5;                 // NOTE: must be non zero
  //  I2caRegs.I2CIER.all = 0x24;      // Enable SCD & ARDY __interrupts
  I2caRegs.I2CMDR.all = 0x0020;         // Take I2C out of reset
  I2caRegs.I2CMDR.bit.RM=0;                 // Disable repeated transmit condition

  I2caRegs.I2CFFTX.all = 0x6000;       // Enable FIFO mode and TXFIFO
  I2caRegs.I2CFFRX.all = 0x2040;       // Enable RXFIFO, clear RXFFINT,
  return;
  }
 
 
 void write_i2c(unsigned char address,unsigned char data)
 {
  while(I2caRegs.I2CMDR.bit.STP == 1)          //wait for i2c  bus to end any prrevious communication
    
  I2caRegs.I2CSAR.all=address;   
    
  while(I2caRegs.I2CSTR.bit.BB == 1);            //wait for to bus free
        
  I2caRegs.I2CDXR.all =0x00;                //write address on which data is to be put
  I2caRegs.I2CDXR.all =data;
                    
   return;    
 }
 
 unsigned char read_i2c(unsigned char address)
 {
   unsigned char data;    
      
   while(I2caRegs.I2CMDR.bit.STP == 1)          //wait for i2c  bus to end any prrevious communication
      
   I2caRegs.I2CSAR.all=address;   
      
   while(I2caRegs.I2CSTR.bit.BB == 1);            //wait for to bus free
   
   data=I2caRegs.I2CDRR.all;                        //read data form
    
  return data;
 }
 
 void start_condition(void)
 {
  I2caRegs.I2CMDR.bit.STT=1;                    //send start condition      
 
  while(I2caRegs.I2CSTR.bit.BB == 1);            //wait for to bus free
 
  return;    
 }
 
 void stop_condition(void)
 {
  I2caRegs.I2CMDR.bit.STP=1;                    //send stop condition      
       
  while(I2caRegs.I2CSTR.bit.BB == 1);            //wait for to bus free
 
  return;    
 }
 

  • Did you already check I2C_Boot.c file available in controlSuite below path. This I2C code doesn't use interrupt.

    Path     : <controlSUITE>\libs\utilities\boot_rom\F2837x_revb\revb_rom_sources\F2837x_bootROM\cpu01-bootROM\source\

    source: I2C_Boot.c


    Regards,

    Manoj

  • Thank,

    I try as you suggest. I write following code to use I2C. But this is still not working. Even the I2C clock is not generating.I put 4.7k for pull up sda and scl. So please help me to find were I making mistake.

    i2c_init1();

    //   GPIO_SetupPinMux(32, GPIO_MUX_CPU2, 0);                    //sck
    //   GPIO_SetupPinOptions(32, GPIO_OUTPUT, GPIO_PUSHPULL);        //cs1

    //   GPIO_SetupPinMux(33, GPIO_MUX_CPU2, 0);                    //sda
    //   GPIO_SetupPinOptions(33, GPIO_OUTPUT, GPIO_PUSHPULL);        //cs2
       data=I2C_CheckKeyVal();

        while(1)     // This is in main body
       {

           data=I2C_CheckKeyVal();
          //data= eeprom_read(0x10);

        //    GPIO_WritePin(92,1); GPIO_WritePin(91,1);
            delay_ms(100);
        //    GPIO_WritePin(92,0); GPIO_WritePin(91,0);
            delay_ms(100);
       }


     //#################################################
     // void I2C_Pinmux_Option2(void)
     //-----------------------------------------------
     // This routine configures GPIO32 and GPIO32
     // as I2C pins :-
     //     1) Pull up enabled on GPIO32 & GPIO33
     //     2) Configure GPIO32 as SDAA pin
     //     3) Configure GPIO33 as SCLA pin
     //      4) Configure GPIO32 & GPIO33 as asynchronous I/O's
     //-----------------------------------------------

     Uint16 I2C_CheckKeyVal(void)
     {
        // To read a word from the EEPROM, an address must be given first in
        // master transmitter mode. Then a restart is performed and data can
        // be read back in master receiver mode.
        I2caRegs.I2CCNT = 0x02;                // Setup how many bytes to send
        I2caRegs.I2CDXR.all = 0x00;                // Configure fifo data for byte
        I2caRegs.I2CDXR.all = 0x00;                //   address of 0x0000

        I2caRegs.I2CMDR.all = 0x2620;        // Send data to setup EEPROM address

        while (I2caRegs.I2CSTR.bit.ARDY == 0) // Wait until communication
        {                                     //   complete and registers ready
           ;
        }

        if (I2caRegs.I2CSTR.bit.NACK == 1)    // Set stop bit & return error if
        {                                    //    NACK received
           I2caRegs.I2CMDR.bit.STP = 1;
           return 0;
        }

        // Check to make sure key value received is correct
         if (I2C_GetWord() != 0x08AA) {return 0;}

        return 1;
     }



     unsigned int i2c_init1(void)
     {
            if(DevCfgRegs.DC10.bit.I2C_A != 0x01)            //check weather the I2C is anable or not
            {
                return 0xFFFFFFFF;
            }

                //Assign GetWordData to the I2C-A version of the
                //function.  GetWordData is a pointer to a function.
                //GetWordData = I2C_GetWord;

               EALLOW;
               CpuSysRegs.PCLKCR9.bit.I2C_A = 1;    // Turn I2C module clock on
               EDIS;

               // Initialize I2C in master transmitter mode
               I2caRegs.I2CSAR.all  = 0x0050;    // Slave address - EEPROM control code
               I2caRegs.I2CPSC.all = 0;            // I2C clock should be between 7Mhz-12Mhz
               I2caRegs.I2CCLKL = 43;            // Pre scalers set for 100kHz bit rate
               I2caRegs.I2CCLKH = 43;            // At a 10Mhz I2C clock

               I2caRegs.I2CMDR.all = 0x0620;    // Master transmitter
                                                   // Take I2C out of reset
                                                   // Stop when suspended

               I2caRegs.I2CFFTX.all = 0x6000;    // Enable FIFO mode and TXFIFO
               I2caRegs.I2CFFRX.all = 0x2000;    // Enable RXFIFO

               I2C_Pinmux_Option1();                            //configure the GPIO for I2C
     return (0x00);
     }


     void I2C_Pinmux_Option1(void)
     {
         EALLOW;
           GpioCtrlRegs.GPCPUD.all &= 0xE7FFFFFF;

           GpioCtrlRegs.GPCGMUX2.all |= 0x01400000;
           GpioCtrlRegs.GPCMUX2.all |= 0x02800000;

           GpioCtrlRegs.GPCQSEL2.all |= 0x03C00000;
         EDIS;
     }


     Uint16 I2C_GetWord(void)
     {
        Uint16 LowByte;

        I2caRegs.I2CCNT = 2;                    // Setup how many bytes to expect
        I2caRegs.I2CMDR.all = 0x2C20;        // Send start as master receiver

        // Wait until communication done
        while (I2caRegs.I2CMDR.bit.STP == 1) {}

        // Combine two bytes to one word & return
        LowByte = I2caRegs.I2CDRR.all;
        return (LowByte | (I2caRegs.I2CDRR.all<<8));
     }




  • All the I2C registers are EALLOW protected. It looks like your EALLOW is disabled when you configure you I2C. So, your code didn't configure I2C.

    Make sure to execute EALLOW instruction before you execute I2C config statements. Also, when you single step though the code, check whether you configurations are making to I2C registers in memory window.

    Regards,
    Manoj
  • Is this issue resolved? Can I close this ticket?