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.

F28335 I2C例程求助,缺失i2c_eeprom_isr.c

Other Parts Discussed in Thread: CONTROLSUITE

在例程C:\ti\controlSUITE\device_support\f2833x\v142\DSP2833x_examples_ccsv5\i2c_eeprom中  Example_2833xI2C_eeprom.c里面如图所示圈出来的地方所提到的i2c_eeprom_isr.c我再项目里没有找到?请问是本来就没有吗,希望得到回复,万分感谢!

  • 在例程C:\ti\controlSUITE\device_support\f2833x\v142\DSP2833x_examples_ccsv5\i2c_eeprom中  Example_2833xI2C_eeprom.c里面如图所示圈出来的地方所提到的i2c_eeprom_isr.c我再项目里没有找到?请问是本来就没有吗,希望得到回复,万分感谢!

  • 这个确实文件中没有,例程中也只是提到了一下,没有实际使用。
    如果你确实需要这个文件的话我去咨询一下美国工程师,看具体是哪里提供的。
  • 你好,因为我不太确定这个例程中是否有用到这个.c中的内容,如果没有的话我就不需要了
  • 没用中断,能编译过去就不需要,例程中未使用
  • 下面相关例程请查看

    1. // TI File $Revision: /main/10 $   
    2. // Checkin $Date: April 21, 2008   15:43:02 $   
    3. //###########################################################################   
    4. //   
    5. // FILE:    Example_2833xI2c_eeprom.c   
    6. //   
    7. // TITLE:   DSP2833x I2C EEPROM Example   
    8. //   
    9. // ASSUMPTIONS:   
    10. //   
    11. //    This program requires the DSP2833x header files.   
    12. //   
    13. //    This program requires an external I2C EEPROM connected to   
    14. //    the I2C bus at address 0x50.   
    15. //   
    16. //    As supplied, this project is configured for "boot to SARAM"   
    17. //    operation.  The 2833x Boot Mode table is shown below.   
    18. //    For information on configuring the boot mode of an eZdsp,   
    19. //    please refer to the documentation included with the eZdsp,   
    20. //   
    21. //       $Boot_Table:   
    22. //   
    23. //         GPIO87   GPIO86     GPIO85   GPIO84   
    24. //          XA15     XA14       XA13     XA12   
    25. //           PU       PU         PU       PU   
    26. //        ==========================================   
    27. //            1        1          1        1    Jump to Flash   
    28. //            1        1          1        0    SCI-A boot   
    29. //            1        1          0        1    SPI-A boot   
    30. //            1        1          0        0    I2C-A boot   
    31. //            1        0          1        1    eCAN-A boot   
    32. //            1        0          1        0    McBSP-A boot   
    33. //            1        0          0        1    Jump to XINTF x16   
    34. //            1        0          0        0    Jump to XINTF x32   
    35. //            0        1          1        1    Jump to OTP   
    36. //            0        1          1        0    Parallel GPIO I/O boot   
    37. //            0        1          0        1    Parallel XINTF boot   
    38. //            0        1          0        0    Jump to SARAM       <- "boot to SARAM"   
    39. //            0        0          1        1    Branch to check boot mode   
    40. //            0        0          1        0    Boot to flash, bypass ADC cal   
    41. //            0        0          0        1    Boot to SARAM, bypass ADC cal   
    42. //            0        0          0        0    Boot to SCI-A, bypass ADC cal   
    43. //                                              Boot_Table_End$   
    44. //   
    45. // DESCRIPTION:   
    46. //   
    47. //    This program will write 1-14 words to EEPROM and read them back.   
    48. //    The data written and the EEPROM address written to are contained   
    49. //    in the message structure, I2cMsgOut1. The data read back will be   
    50. //    contained in the message structure I2cMsgIn1.   
    51. //   
    52. //    This program will work with the on-board I2C EEPROM supplied on   
    53. //    the F2833x eZdsp.   
    54. //   
    55. //   
    56. //###########################################################################   
    57. // Original Author: D.F.   
    58. //   
    59. // $TI Release: DSP2833x/DSP2823x C/C++ Header Files V1.31 $   
    60. // $Release Date: August 4, 2009 $   
    61. //###########################################################################   
    62. #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File   
    63. // Note: I2C Macros used in this example can be found in the   
    64. // DSP2833x_I2C_defines.h file   
    65. // Prototype statements for functions found within this file.   
    66. void   I2CA_Init(void);   
    67. Uint16 I2CA_WriteData(struct I2CMSG *msg);   
    68. Uint16 I2CA_ReadData(struct I2CMSG *msg);   
    69. interrupt void i2c_int1a_isr(void);   
    70. void pass(void);   
    71. void fail(void);   
    72. #define I2C_SLAVE_ADDR        0x50   
    73. #define I2C_NUMBYTES          4   
    74. #define I2C_EEPROM_HIGH_ADDR  0x00   
    75. #define I2C_EEPROM_LOW_ADDR   0x30   
    76. // Global variables   
    77. // Two bytes will be used for the outgoing address,   
    78. // thus only setup 14 bytes maximum   
    79. struct I2CMSG I2cMsgOut1={I2C_MSGSTAT_SEND_WITHSTOP,   
    80.                           I2C_SLAVE_ADDR,   
    81.                           I2C_NUMBYTES,   
    82.                           I2C_EEPROM_HIGH_ADDR,   
    83.                           I2C_EEPROM_LOW_ADDR,   
    84.                           0x12,                   // Msg Byte 1   
    85.                           0x34,                   // Msg Byte 2   
    86.                           0x56,                   // Msg Byte 3   
    87.                           0x78,                   // Msg Byte 4   
    88.                           0x9A,                   // Msg Byte 5   
    89.                           0xBC,                   // Msg Byte 6   
    90.                           0xDE,                   // Msg Byte 7   
    91.                           0xF0,                   // Msg Byte 8   
    92.                           0x11,                   // Msg Byte 9   
    93.                           0x10,                   // Msg Byte 10   
    94.                           0x11,                   // Msg Byte 11   
    95.                           0x12,                   // Msg Byte 12   
    96.                           0x13,                   // Msg Byte 13   
    97.                           0x12};                  // Msg Byte 14   
    98. struct I2CMSG I2cMsgIn1={ I2C_MSGSTAT_SEND_NOSTOP,   
    99.                           I2C_SLAVE_ADDR,   
    100.                           I2C_NUMBYTES,   
    101.                           I2C_EEPROM_HIGH_ADDR,   
    102.                           I2C_EEPROM_LOW_ADDR};   
    103. struct I2CMSG *CurrentMsgPtr;               // Used in interrupts   
    104. Uint16 PassCount;   
    105. Uint16 FailCount;   
    106. void main(void)   
    107. {   
    108.    Uint16 Error;   
    109.    Uint16 i;   
    110.    CurrentMsgPtr = &I2cMsgOut1;   
    111. // Step 1. Initialize System Control:   
    112. // PLL, WatchDog, enable Peripheral Clocks   
    113. // This example function is found in the DSP2833x_SysCtrl.c file.   
    114.    InitSysCtrl();   
    115. // Step 2. Initalize GPIO:   
    116. // This example function is found in the DSP2833x_Gpio.c file and   
    117. // illustrates how to set the GPIO to it's default state.   
    118. // InitGpio();   
    119. // Setup only the GP I/O only for I2C functionality   
    120.    InitI2CGpio();   
    121. // Step 3. Clear all interrupts and initialize PIE vector table:   
    122. // Disable CPU interrupts   
    123.    DINT;   
    124. // Initialize PIE control registers to their default state.   
    125. // The default state is all PIE interrupts disabled and flags   
    126. // are cleared.   
    127. // This function is found in the DSP2833x_PieCtrl.c file.   
    128.    InitPieCtrl();   
    129. // Disable CPU interrupts and clear all CPU interrupt flags:   
    130.    IER = 0x0000;   
    131.    IFR = 0x0000;   
    132. // Initialize the PIE vector table with pointers to the shell Interrupt   
    133. // Service Routines (ISR).   
    134. // This will populate the entire table, even if the interrupt   
    135. // is not used in this example.  This is useful for debug purposes.   
    136. // The shell ISR routines are found in DSP2833x_DefaultIsr.c.   
    137. // This function is found in DSP2833x_PieVect.c.   
    138.    InitPieVectTable();   
    139. // Interrupts that are used in this example are re-mapped to   
    140. // ISR functions found within this file.   
    141.    EALLOW;  // This is needed to write to EALLOW protected registers   
    142.    PieVectTable.I2CINT1A = &i2c_int1a_isr;   
    143.    EDIS;   // This is needed to disable write to EALLOW protected registers   
    144. // Step 4. Initialize all the Device Peripherals:   
    145. // This function is found in DSP2833x_InitPeripherals.c   
    146. // InitPeripherals(); // Not required for this example   
    147.    I2CA_Init();   
    148. // Step 5. User specific code   
    149.    // Clear Counters   
    150.    PassCount = 0;   
    151.    FailCount = 0;   
    152.    // Clear incoming message buffer   
    153.    for (i = 0; i < I2C_MAX_BUFFER_SIZE; i++)   
    154.    {   
    155.        I2cMsgIn1.MsgBuffer[i] = 0x0000;   
    156.    }   
    157. // Enable interrupts required for this example   
    158. // Enable I2C interrupt 1 in the PIE: Group 8 interrupt 1   
    159.    PieCtrlRegs.PIEIER8.bit.INTx1 = 1;   
    160. // Enable CPU INT8 which is connected to PIE group 8   
    161.    IER |= M_INT8;   
    162.    EINT;   
    163.    // Application loop   
    164.    for(;;)   
    165.    {   
    166.       //////////////////////////////////   
    167.       // Write data to EEPROM section //   
    168.       //////////////////////////////////   
    169.       // Check the outgoing message to see if it should be sent.   
    170.       // In this example it is initialized to send with a stop bit.   
    171.       if(I2cMsgOut1.MsgStatus == I2C_MSGSTAT_SEND_WITHSTOP)   
    172.       {   
    173.          Error = I2CA_WriteData(&I2cMsgOut1);   
    174.          // If communication is correctly initiated, set msg status to busy   
    175.          // and update CurrentMsgPtr for the interrupt service routine.   
    176.          // Otherwise, do nothing and try again next loop. Once message is   
    177.          // initiated, the I2C interrupts will handle the rest. Search for   
    178.          // ICINTR1A_ISR in the i2c_eeprom_isr.c file.   
    179.          if (Error == I2C_SUCCESS)   
    180.          {   
    181.             CurrentMsgPtr = &I2cMsgOut1;   
    182.             I2cMsgOut1.MsgStatus = I2C_MSGSTAT_WRITE_BUSY;   
    183.          }   
    184.       }  // end of write section   
    185.       ///////////////////////////////////   
    186.       // Read data from EEPROM section //   
    187.       ///////////////////////////////////   
    188.       // Check outgoing message status. Bypass read section if status is   
    189.       // not inactive.   
    190.       if (I2cMsgOut1.MsgStatus == I2C_MSGSTAT_INACTIVE)   
    191.       {   
    192.          // Check incoming message status.   
    193.          if(I2cMsgIn1.MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)   
    194.          {   
    195.             // EEPROM address setup portion   
    196.             while(I2CA_ReadData(&I2cMsgIn1) != I2C_SUCCESS)   
    197.             {   
    198.                // Maybe setup an attempt counter to break an infinite while   
    199.                // loop. The EEPROM will send back a NACK while it is performing   
    200.                // a write operation. Even though the write communique is   
    201.                // complete at this point, the EEPROM could still be busy   
    202.                // programming the data. Therefore, multiple attempts are   
    203.                // necessary.   
    204.             }   
    205.             // Update current message pointer and message status   
    206.             CurrentMsgPtr = &I2cMsgIn1;   
    207.             I2cMsgIn1.MsgStatus = I2C_MSGSTAT_SEND_NOSTOP_BUSY;   
    208.          }   
    209.          // Once message has progressed past setting up the internal address   
    210.          // of the EEPROM, send a restart to read the data bytes from the   
    211.          // EEPROM. Complete the communique with a stop bit. MsgStatus is   
    212.          // updated in the interrupt service routine.   
    213.          else if(I2cMsgIn1.MsgStatus == I2C_MSGSTAT_RESTART)   
    214.          {   
    215.             // Read data portion   
    216.             while(I2CA_ReadData(&I2cMsgIn1) != I2C_SUCCESS)   
    217.             {   
    218.                // Maybe setup an attempt counter to break an infinite while   
    219.                // loop.   
    220.             }   
    221.             // Update current message pointer and message status   
    222.             CurrentMsgPtr = &I2cMsgIn1;   
    223.             I2cMsgIn1.MsgStatus = I2C_MSGSTAT_READ_BUSY;   
    224.          }   
    225.       }  // end of read section   
    226.    }   // end of for(;;)   
    227. }   // end of main   
    228. void I2CA_Init(void)   
    229. {   
    230.    // Initialize I2C   
    231.    I2caRegs.I2CSAR = 0x0050;        // Slave address - EEPROM control code   
    232.    #if (CPU_FRQ_150MHZ)             // Default - For 150MHz SYSCLKOUT   
    233.         I2caRegs.I2CPSC.all = 14;   // Prescaler - need 7-12 Mhz on module clk (150/15 = 10MHz)   
    234.    #endif   
    235.    #if (CPU_FRQ_100MHZ)             // For 100 MHz SYSCLKOUT   
    236.      I2caRegs.I2CPSC.all = 9;       // Prescaler - need 7-12 Mhz on module clk (100/10 = 10MHz)   
    237.    #endif   
    238.    I2caRegs.I2CCLKL = 10;           // NOTE: must be non zero   
    239.    I2caRegs.I2CCLKH = 5;            // NOTE: must be non zero   
    240.    I2caRegs.I2CIER.all = 0x24;      // Enable SCD & ARDY interrupts   
    241.    I2caRegs.I2CMDR.all = 0x0020;    // Take I2C out of reset   
    242.                                     // Stop I2C when suspended   
    243.    I2caRegs.I2CFFTX.all = 0x6000;   // Enable FIFO mode and TXFIFO   
    244.    I2caRegs.I2CFFRX.all = 0x2040;   // Enable RXFIFO, clear RXFFINT,   
    245.    return;   
    246. }   
    247. Uint16 I2CA_WriteData(struct I2CMSG *msg)   
    248. {   
    249.    Uint16 i;   
    250.    // Wait until the STP bit is cleared from any previous master communication.   
    251.    // Clearing of this bit by the module is delayed until after the SCD bit is   
    252.    // set. If this bit is not checked prior to initiating a new message, the   
    253.    // I2C could get confused.   
    254.    if (I2caRegs.I2CMDR.bit.STP == 1)   
    255.    {   
    256.       return I2C_STP_NOT_READY_ERROR;   
    257.    }   
    258.    // Setup slave address   
    259.    I2caRegs.I2CSAR = msg->SlaveAddress;   
    260.    // Check if bus busy   
    261.    if (I2caRegs.I2CSTR.bit.BB == 1)   
    262.    {   
    263.       return I2C_BUS_BUSY_ERROR;   
    264.    }   
    265.    // Setup number of bytes to send   
    266.    // MsgBuffer + Address   
    267.    I2caRegs.I2CCNT = msg->NumOfBytes+2;   
    268.    // Setup data to send   
    269.    I2caRegs.I2CDXR = msg->MemoryHighAddr;   
    270.    I2caRegs.I2CDXR = msg->MemoryLowAddr;   
    271. // for (i=0; i<msg->NumOfBytes-2; i++)   
    272.    for (i=0; i<msg->NumOfBytes; i++)   
    273.    {   
    274.       I2caRegs.I2CDXR = *(msg->MsgBuffer+i);   
    275.    }   
    276.    // Send start as master transmitter   
    277.    I2caRegs.I2CMDR.all = 0x6E20;   
    278.    return I2C_SUCCESS;   
    279. }   
    280. Uint16 I2CA_ReadData(struct I2CMSG *msg)   
    281. {   
    282.    // Wait until the STP bit is cleared from any previous master communication.   
    283.    // Clearing of this bit by the module is delayed until after the SCD bit is   
    284.    // set. If this bit is not checked prior to initiating a new message, the   
    285.    // I2C could get confused.   
    286.    if (I2caRegs.I2CMDR.bit.STP == 1)   
    287.    {   
    288.       return I2C_STP_NOT_READY_ERROR;   
    289.    }   
    290.    I2caRegs.I2CSAR = msg->SlaveAddress;   
    291.    if(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)   
    292.    {   
    293.       // Check if bus busy   
    294.       if (I2caRegs.I2CSTR.bit.BB == 1)   
    295.       {   
    296.          return I2C_BUS_BUSY_ERROR;   
    297.       }   
    298.       I2caRegs.I2CCNT = 2;   
    299.       I2caRegs.I2CDXR = msg->MemoryHighAddr;   
    300.       I2caRegs.I2CDXR = msg->MemoryLowAddr;   
    301.       I2caRegs.I2CMDR.all = 0x2620;         // Send data to setup EEPROM address   
    302.    }   
    303.    else if(msg->MsgStatus == I2C_MSGSTAT_RESTART)   
    304.    {   
    305.       I2caRegs.I2CCNT = msg->NumOfBytes; // Setup how many bytes to expect   
    306.       I2caRegs.I2CMDR.all = 0x2C20;         // Send restart as master receiver   
    307.    }   
    308.    return I2C_SUCCESS;   
    309. }   
    310. interrupt void i2c_int1a_isr(void)     // I2C-A   
    311. {   
    312.    Uint16 IntSource, i;   
    313.    // Read interrupt source   
    314.    IntSource = I2caRegs.I2CISRC.all;   
    315.    // Interrupt source = stop condition detected   
    316.    if(IntSource == I2C_SCD_ISRC)   
    317.    {   
    318.       // If completed message was writing data, reset msg to inactive state   
    319.       if (CurrentMsgPtr->MsgStatus == I2C_MSGSTAT_WRITE_BUSY)   
    320.       {   
    321.          CurrentMsgPtr->MsgStatus = I2C_MSGSTAT_INACTIVE;   
    322.       }   
    323.       else   
    324.       {   
    325.          // If a message receives a NACK during the address setup portion of the   
    326.          // EEPROM read, the code further below included in the register access ready   
    327.          // interrupt source code will generate a stop condition. After the stop   
    328.          // condition is received (here), set the message status to try again.   
    329.          // User may want to limit the number of retries before generating an error.   
    330.          if(CurrentMsgPtr->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP_BUSY)   
    331.          {   
    332.             CurrentMsgPtr->MsgStatus = I2C_MSGSTAT_SEND_NOSTOP;   
    333.          }   
    334.          // If completed message was reading EEPROM data, reset msg to inactive state   
    335.          // and read data from FIFO.   
    336.          else if (CurrentMsgPtr->MsgStatus == I2C_MSGSTAT_READ_BUSY)   
    337.          {   
    338.             CurrentMsgPtr->MsgStatus = I2C_MSGSTAT_INACTIVE;   
    339.             for(i=0; i < I2C_NUMBYTES; i++)   
    340.             {   
    341.               CurrentMsgPtr->MsgBuffer[i] = I2caRegs.I2CDRR;   
    342.             }   
    343.          {   
    344.          // Check recieved data   
    345.          for(i=0; i < I2C_NUMBYTES; i++)   
    346.          {   
    347.             if(I2cMsgIn1.MsgBuffer[i] == I2cMsgOut1.MsgBuffer[i])   
    348.             {   
    349.                 PassCount++;   
    350.             }   
    351.             else   
    352.             {   
    353.                 FailCount++;   
    354.             }   
    355.          }   
    356.          if(PassCount == I2C_NUMBYTES)   
    357.          {   
    358.             pass();   
    359.          }   
    360.          else   
    361.          {   
    362.             fail();   
    363.          }   
    364.       }   
    365.     }   
    366.       }   
    367.    }  // end of stop condition detected   
    368.    // Interrupt source = Register Access Ready   
    369.    // This interrupt is used to determine when the EEPROM address setup portion of the   
    370.    // read data communication is complete. Since no stop bit is commanded, this flag   
    371.    // tells us when the message has been sent instead of the SCD flag. If a NACK is   
    372.    // received, clear the NACK bit and command a stop. Otherwise, move on to the read   
    373.    // data portion of the communication.   
    374.    else if(IntSource == I2C_ARDY_ISRC)   
    375.    {   
    376.       if(I2caRegs.I2CSTR.bit.NACK == 1)   
    377.       {   
    378.          I2caRegs.I2CMDR.bit.STP = 1;   
    379.          I2caRegs.I2CSTR.all = I2C_CLR_NACK_BIT;   
    380.       }   
    381.       else if(CurrentMsgPtr->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP_BUSY)   
    382.       {   
    383.          CurrentMsgPtr->MsgStatus = I2C_MSGSTAT_RESTART;   
    384.       }   
    385.    }  // end of register access ready   
    386.    else   
    387.    {   
    388.       // Generate some error due to invalid interrupt source   
    389.       asm("   ESTOP0");   
    390.    }   
    391.    // Enable future I2C (PIE Group 8) interrupts   
    392.    PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;   
    393. }   
    394. void pass()   
    395. {   
    396.     asm("   ESTOP0");   
    397.     for(;;);   
    398. }   
    399. void fail()   
    400. {   
    401.     asm("   ESTOP0");   
    402.     for(;;);   
    403. }   
    404. //===========================================================================   
    405. // No more.   

    //===========================================================================