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.
想以写寄存器的方式进行配置
目前给出的都是driverlib下的例程
写寄存器的话,您可以根据用户指南的寄存器结合driverlib下的例程的I2C配置注释说明来写
您可以参考一下
C:\ti\c2000\C2000Ware_3_04_00_00\driverlib\f2838x\driverlib_cm\inc
下的 hw_i2c.h 以及 C:\ti\c2000\C2000Ware_3_04_00_00\driverlib\f2838x\driverlib_cm 下的i2c文件
这个我看了,这都是封装好的写地址的方式,封装后写的不清不楚的,而且例程太简单了,管脚都没定义,我自己写我想写寄存器的方式,这样方便写,起码CPU以前都是写寄存器的知道怎么写,那个例程看了跟没看似的,没有用
// // Included Files // #include <stdint.h> #include <stdbool.h> #include "cm.h" // // Defines // #define SLAVE_ADDRESS 0x3C #define NUM_I2C_DATA 3 #define PASS 0 #define FAIL 1 int Ucount; // Globals // uint32_t result = FAIL; uint32_t ui32DataTx; static uint32_t ui32DataRx; // // Function Prototypes // void initI2C(void); __interrupt void I2C0SlaveIntHandler(void); // // Main // void main(void) { uint16_t i; // // disable WD, enable peripheral clocks. // CM_init(); // // Enable the I2C0 interrupt on the processor (NVIC). // I2C_registerInt(INT_I2C0,I2C0SlaveIntHandler); // // Set I2C use, initializing master and slave // initI2C(); // // Initialize the data to send. // ui32DataTx = 'I'; // // Place the data to be sent in the data register. // I2C_putMasterData(I2C0_BASE, ui32DataTx); // // Initiate send of single piece of data from the master. Since the // loopback mode is enabled, the Master and Slave units are connected // allowing us to receive the same data that we sent out. // I2C_setMasterConfig(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND); while(1) { // // Delay // for(i=1000; i>0; i--); Ucount++;if(Ucount>256) Ucount=0; I2C_putMasterData(I2C0_BASE, Ucount); I2C_setMasterConfig(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND); } } // // Function to configure I2C0. // void initI2C() { // // Enable the Master module. // I2C_enableMaster(I2C0_BASE); // // I2C configuration. Set up to transfer data at 100 Kbps. // I2C_initMaster(I2C0_BASE,I2C_CLK_FREQ,false); // // Enable the Slave module. // I2C_enableSlave(I2C0_BASE); // // Configure for internal loopback mode // I2C_setSlaveAddress(I2C0_BASE,SLAVE_ADDRESS,I2C_MASTER_WRITE); I2C_setOwnSlaveAddress(I2C0_BASE,I2C_SLAVE_ADDR_PRIMARY,SLAVE_ADDRESS); // I2C_enableLoopback(I2C0_BASE); // // Configure and turn on the I2C0 slave interrupt. The I2C_enableSlaveInt() // gives you the ability to only enable specific interrupts. For this case // we are only interrupting when the slave device receives data. // I2C_enableSlaveInt(I2C0_BASE); } // // I2C0 Receive ISR. // __interrupt void I2C0SlaveIntHandler(void) { uint32_t slvStatus; // // Get the slave interrupt status // slvStatus = I2C_getSlaveIntStatus(I2C0_BASE,I2C_MASTER_RAW_INT); // // Clear the I2C0 interrupt flag. // I2C_clearSlaveInt(I2C0_BASE); // // Read the data from the slave. // ui32DataRx = I2C_getSlaveData(I2C0_BASE); if(ui32DataRx != ui32DataTx) result = FAIL; else result = PASS; // // Clear the slave interrupt status // I2C_clearSlaveIntSource(I2C0_BASE,slvStatus); } // // End of File //
//############################################################################# // // FILE: cm_common_config_c28x.c // // TITLE: C28x Common Configurations to be used for the CM Side. // //! \addtogroup driver_example_list //! <h1>C28x Common Configurations</h1> //! //! This example configures the GPIOs and Allocates the shared peripherals //! according to the defines selected by the users. //! // //############################################################################# // $TI Release: F2838x Support Library v3.04.00.00 $ // $Release Date: Fri Feb 12 19:08:49 IST 2021 $ // $Copyright: // Copyright (C) 2021 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //############################################################################# // // Included Files // #include "driverlib.h" #include "device.h" void main(void) { // // Initialize device clock and peripherals // Device_init(); // // Boot CM core // #ifdef _FLASH Device_bootCM(BOOTMODE_BOOT_TO_FLASH_SECTOR0); #else Device_bootCM(BOOTMODE_BOOT_TO_S0RAM); #endif // // Disable pin locks and enable internal pull-ups. // Device_initGPIO(); GPIO_setPinConfig(GPIO_31_CM_I2CA_SDA); GPIO_setPinConfig(GPIO_32_CM_I2CA_SCL); GPIO_setPadConfig(45, GPIO_PIN_TYPE_STD); GPIO_setPinConfig(GPIO_45_GPIO45); GPIO_setDirectionMode(45, GPIO_DIR_MODE_OUT); GPIO_setMasterCore(45, GPIO_CORE_CM); #ifdef ETHERNET // // Set up EnetCLK to use SYSPLL as the clock source and set the // clock divider to 2. // // This way we ensure that the PTP clock is 100 MHz. Note that this value // is not automatically/dynamically known to the CM core and hence it needs // to be made available to the CM side code beforehand. SysCtl_setEnetClk(SYSCTL_ENETCLKOUT_DIV_2, SYSCTL_SOURCE_SYSPLL); // // Configure the GPIOs for ETHERNET. // // // MDIO Signals // GPIO_setPinConfig(GPIO_105_ENET_MDIO_CLK); GPIO_setPinConfig(GPIO_106_ENET_MDIO_DATA); // // Use this only for RMII Mode //GPIO_setPinConfig(GPIO_73_ENET_RMII_CLK); // // //MII Signals // GPIO_setPinConfig(GPIO_109_ENET_MII_CRS); GPIO_setPinConfig(GPIO_110_ENET_MII_COL); GPIO_setPinConfig(GPIO_75_ENET_MII_TX_DATA0); GPIO_setPinConfig(GPIO_122_ENET_MII_TX_DATA1); GPIO_setPinConfig(GPIO_123_ENET_MII_TX_DATA2); GPIO_setPinConfig(GPIO_124_ENET_MII_TX_DATA3); // //Use this only if the TX Error pin has to be connected //GPIO_setPinConfig(GPIO_46_ENET_MII_TX_ERR); // GPIO_setPinConfig(GPIO_118_ENET_MII_TX_EN); GPIO_setPinConfig(GPIO_114_ENET_MII_RX_DATA0); GPIO_setPinConfig(GPIO_115_ENET_MII_RX_DATA1); GPIO_setPinConfig(GPIO_116_ENET_MII_RX_DATA2); GPIO_setPinConfig(GPIO_117_ENET_MII_RX_DATA3); GPIO_setPinConfig(GPIO_113_ENET_MII_RX_ERR); GPIO_setPinConfig(GPIO_112_ENET_MII_RX_DV); GPIO_setPinConfig(GPIO_44_ENET_MII_TX_CLK); GPIO_setPinConfig(GPIO_111_ENET_MII_RX_CLK); // //Power down pin to bring the external PHY out of Power down // GPIO_setDirectionMode(108, GPIO_DIR_MODE_OUT); GPIO_setPadConfig(108, GPIO_PIN_TYPE_PULLUP); GPIO_writePin(108,1); // //PHY Reset Pin to be driven High to bring external PHY out of Reset // GPIO_setDirectionMode(119, GPIO_DIR_MODE_OUT); GPIO_setPadConfig(119, GPIO_PIN_TYPE_PULLUP); GPIO_writePin(119,1); #endif #ifdef MCAN // // Setting the MCAN Clock. // SysCtl_setMCANClk(SYSCTL_MCANCLK_DIV_4); // // Configuring the GPIOs for MCAN. // GPIO_setPinConfig(DEVICE_GPIO_CFG_MCANRXA); GPIO_setPinConfig(DEVICE_GPIO_CFG_MCANTXA); #endif #ifdef CANA // // Configuring the GPIOs for CAN A. // GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA); GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA); // // Allocate Shared Peripheral CAN A to the CM Side. // SysCtl_allocateSharedPeripheral(SYSCTL_PALLOCATE_CAN_A,0x1U); #endif #ifdef CANB // // Configuring the GPIOs for CAN B. // GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXB); GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXB); // // Allocate Shared Peripheral CAN B to the CM Side. // SysCtl_allocateSharedPeripheral(SYSCTL_PALLOCATE_CAN_B,0x1U); #endif #ifdef UART // // Configure GPIO85 as the UART Rx pin. // GPIO_setPinConfig(GPIO_85_UARTA_RX); GPIO_setDirectionMode(85, GPIO_DIR_MODE_IN); GPIO_setPadConfig(85, GPIO_PIN_TYPE_STD); GPIO_setQualificationMode(85, GPIO_QUAL_ASYNC); // // Configure GPIO84 as the UART Tx pin. // GPIO_setPinConfig(GPIO_84_UARTA_TX); GPIO_setDirectionMode(84, GPIO_DIR_MODE_OUT); GPIO_setPadConfig(84, GPIO_PIN_TYPE_STD); GPIO_setQualificationMode(84, GPIO_QUAL_ASYNC); #endif #ifdef USB #ifdef USE_20MHZ_XTAL // // Set up the auxiliary PLL so a 60 MHz output clock is provided to the USB module. // This fixed frequency is required for all USB operations. // SysCtl_setAuxClock(SYSCTL_AUXPLL_OSCSRC_XTAL | SYSCTL_AUXPLL_IMULT(48) | SYSCTL_REFDIV(2U) | SYSCTL_ODIV(4U) | SYSCTL_AUXPLL_DIV_2 | SYSCTL_AUXPLL_ENABLE | SYSCTL_DCC_BASE_0); #else // // Set up the auxiliary PLL so a 60 MHz output clock is provided to the USB module. // This fixed frequency is required for all USB operations. // SysCtl_setAuxClock(SYSCTL_AUXPLL_OSCSRC_XTAL | SYSCTL_AUXPLL_IMULT(48) | SYSCTL_REFDIV(2U) | SYSCTL_ODIV(5U) | SYSCTL_AUXPLL_DIV_2 | SYSCTL_AUXPLL_ENABLE | SYSCTL_DCC_BASE_0); #endif // // Allocate Shared Peripheral USB to the CM Side. // SysCtl_allocateSharedPeripheral(SYSCTL_PALLOCATE_USBA, 1); GPIO_setPinConfig(GPIO_0_GPIO0); GPIO_setPadConfig(0, GPIO_PIN_TYPE_STD); GPIO_setDirectionMode(0, GPIO_DIR_MODE_OUT); GPIO_setMasterCore(0, GPIO_CORE_CM); // // Set the master core of GPIOs to CM. // GPIO_setMasterCore(42, GPIO_CORE_CM); GPIO_setMasterCore(43, GPIO_CORE_CM); GPIO_setMasterCore(46, GPIO_CORE_CM); GPIO_setMasterCore(47, GPIO_CORE_CM); GPIO_setMasterCore(120, GPIO_CORE_CM); GPIO_setMasterCore(121, GPIO_CORE_CM); // // Set the USB DM and DP GPIOs. // GPIO_setAnalogMode(42, GPIO_ANALOG_ENABLED); GPIO_setAnalogMode(43, GPIO_ANALOG_ENABLED); // // Set the direction for VBUS and ID. // GPIO_setDirectionMode(46, GPIO_DIR_MODE_IN); GPIO_setDirectionMode(47, GPIO_DIR_MODE_IN); // // Configure the Power Fault. // GPIO_setMasterCore(120, GPIO_CORE_CM); GPIO_setDirectionMode(120, GPIO_DIR_MODE_IN); // // Configure the External Power Signal Enable. // GPIO_setMasterCore(121, GPIO_CORE_CM); GPIO_setDirectionMode(121, GPIO_DIR_MODE_OUT); GPIO_writePin(121, 1); // // Set the CM Clock to run at 120MHz. // The CM Clock is a fractional multiple of the AUXPLL Clock (120 Mhz) from // which the USB Clock (60 MHz) is derived. // SysCtl_setCMClk(SYSCTL_CMCLKOUT_DIV_1, SYSCTL_SOURCE_AUXPLL); #endif }
就是这个例程简单的改了一下连续发送,
问题1:禁止I2C_enableLoopback(I2C0_BASE);为什么还能进接收中断
问题2:为什么测试32管教没有波形
问题3:想确定这里的解释有没有写反,为什么I2C_MASTER_WRITE是读 那个是写