主题: SysConfig 中讨论的其他器件
工具/软件:
您好 TI 社区、
我尝试使用 I2C 通信协议将 MCP79410 RTC IC 与 TMS320F2800137微控制器连接。 我使用 MCU 的 I2C 引脚进行该连接。 但是、我没有看到 SDA 线路上有任何数据活动、似乎也没有发生通信。
以下是我所做的工作:
用4.7k 上拉电阻连接 SCL 和 SDA 线路。
在主/发送器模式下配置的 I2C。
已验证 I2C 线路的引脚多路复用。
根据数据表、MCP79410地址为0x6F。
以下是我所做的工作:
使用10k 上拉电阻器连接 SCL 和 SDA 线路。
在主/发送器模式下配置的 I2C。
已验证 I2C 线路的引脚多路复用。
根据数据表、MCP79410地址为0x6F。
我已附上:
1.我使用的源代码。
//############################################################################# // // FILE: empty_driverlib_main.c // //! \addtogroup driver_example_list //! <h1>Empty Project Example</h1> //! //! This example is an empty project setup for Driverlib development. //! // //############################################################################# // // // $Copyright: // Copyright (C) 2024 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" #include "board.h" #include "c2000ware_libraries.h" #define MCP79410_ADDRESS 0x6F uint8_t hours, minutes, seconds; void RTC_setTime(uint8_t hours, uint8_t minutes, uint8_t seconds); void RTC_getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds); // // ===== Function Prototypes ===== void initI2C(void); // void mcp79410_writeByte(uint8_t regAddr, uint8_t data); // uint8_t mcp79410_readByte(uint8_t regAddr); void mcp79410_setTime(void); void mcp79410_readTime(void); // uint8_t bcdToDec(uint8_t val); // uint8_t data; // uint8_t raw_seconds; // uint8_t raw_minutes; // uint8_t raw_hours; // uint8_t seconds; // uint8_t minutes; // uint8_t hours; // uint8_t i; // uint8_t timeData[3]; // // Main // void main(void) { // // Initialize device clock and peripherals // Device_init(); // // Disable pin locks and enable internal pull-ups. // Device_initGPIO(); // // Initialize PIE and clear PIE registers. Disables CPU interrupts. // Interrupt_initModule(); // // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // Interrupt_initVectorTable(); // // PinMux and Peripheral Initialization // Board_init(); // // C2000Ware Library initialization // C2000Ware_libraries_init(); // // Enable Global Interrupt (INTM) and real time interrupt (DBGM) // // EINT; // ERTM; initI2C(); I2C_setSlaveAddress(I2CA_BASE, MCP79410_ADDRESS); // Set RTC address RTC_setTime(12, 30, 45); // Set time to 12:30:45 while (1) { RTC_getTime(&hours, &minutes, &seconds); DEVICE_DELAY_US(1000000); // Delay 1 second } } // // End of File // void initI2C(void) { // I2C SDA and SCL pin setup GPIO_setPinConfig(GPIO_32_I2CA_SDA); GPIO_setPadConfig(33, GPIO_PIN_TYPE_PULLUP); GPIO_setQualificationMode(33, GPIO_QUAL_ASYNC); GPIO_setPinConfig(GPIO_33_I2CA_SCL); GPIO_setPadConfig(32, GPIO_PIN_TYPE_PULLUP); GPIO_setQualificationMode(32, GPIO_QUAL_ASYNC); // I2C Master config I2C_disableModule(I2CA_BASE); I2C_initMaster(I2CA_BASE, DEVICE_SYSCLK_FREQ, 100000, I2C_DUTYCYCLE_33); I2C_setAddressMode(I2CA_BASE, I2C_ADDR_MODE_7BITS); I2C_setBitCount(I2CA_BASE, I2C_BITCOUNT_8); I2C_setSlaveAddress(I2CA_BASE, MCP79410_ADDRESS); I2C_setEmulationMode(I2CA_BASE, I2C_EMULATION_FREE_RUN); I2C_enableModule(I2CA_BASE); } // void I2C_init(void) { // // Initialize I2C as master // I2C_initMaster(I2CA_BASE, DEVICE_SYSCLK_FREQ, 100000, I2C_DUTYCYCLE_33); // I2C_setSlaveAddress(I2CA_BASE, RTC_I2C_ADDR); // I2C_enableModule(I2CA_BASE); // } void RTC_setTime(uint8_t hours, uint8_t minutes, uint8_t seconds) { I2C_setConfig(I2CA_BASE, I2C_MASTER_SEND_MODE); I2C_sendStartCondition(I2CA_BASE); I2C_putData(I2CA_BASE, 0x00); // Address of seconds register I2C_putData(I2CA_BASE, seconds); I2C_putData(I2CA_BASE, minutes); I2C_putData(I2CA_BASE, hours); I2C_sendStopCondition(I2CA_BASE); } uint8_t bcdToDec(uint8_t val) { return ((val >> 4) * 10 + (val & 0x0F)); } void RTC_getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds) { // Step 1: Set register pointer to 0x00 (seconds register) I2C_setConfig(I2CA_BASE, I2C_MASTER_SEND_MODE); I2C_sendStartCondition(I2CA_BASE); I2C_putData(I2CA_BASE, 0x00); // Point to seconds register while(I2C_isBusBusy(I2CA_BASE)); // Step 2: Repeated start for reading I2C_setConfig(I2CA_BASE, I2C_MASTER_RECEIVE_MODE); I2C_sendStartCondition(I2CA_BASE); uint8_t rawSeconds = I2C_getData(I2CA_BASE); uint8_t rawMinutes = I2C_getData(I2CA_BASE); uint8_t rawHours = I2C_getData(I2CA_BASE); I2C_sendStopCondition(I2CA_BASE); // Step 3: Convert from BCD to decimal *seconds = bcdToDec(rawSeconds & 0x7F); // Mask ST bit *minutes = bcdToDec(rawMinutes); *hours = bcdToDec(rawHours & 0x3F); // Mask 24-hour mode bits }
2. I2C 通信尝试期间 SCL 和 SDA 线路的示波器波形。
如果您能帮助我确定可能出现的问题或我缺少的问题、我将不胜感激。
提前感谢您。