您好!
我正在使用TM4C129ENCPDT Arm 芯片的平台上。 为了进行开发、我使用 EK-TM4C129EXL。
此模块充当 I2C/SMBus 从器件、它将接收充当主器件的主机板的命令。 我的开发板将解析主器件发送给它的命令(以及任何参数)、并在必要时返回任何必要的数据。 为了进行测试、我尝试将器件设置为从模式、并连接 Analog Discovery 2以作为 I2C 主设备发送命令。 理想情况下、一旦从器件接收到 STOP 条件、就会发生中断、允许我从 Rx 缓冲区中提取消息的内容。
我正在使用相应的软件 API 进行开发。
在将 I2C 中断获取到 proc 时遇到问题。 我以前将 AD2用作主器件、因此我怀疑问题可能出在我的 C 代码中的某个位置(张贴在下面)。
//////////////////////////////////////////////// // code in tm4c129encpdt_startup_ccs.c extern void i2cIntHandler(void); ... #pragma DATA_SECTION(g_pfnVectors, ".intvecs") void (* const g_pfnVectors[])(void) = { (void (*)(void))((uint32_t)&__STACK_TOP), // The initial stack pointer ResetISR, // The reset handler NmiSR, // The NMI handler FaultISR, // The hard fault handler ... i2cIntHandler, // I2C0 Master and Slave ... }; //////////////////////////////////////////////// //////////////////////////////////////////////// // code in init.c #include "init.h" #include <stdio.h> #include "inc/hw_i2c.h" #include "inc/hw_memmap.h" #include "driverlib/gpio.h" #include "driverlib/i2c.h" #include "driverlib/interrupt.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" void i2cIntHandler(void) { uint8_t buffer[4] = {0}; uint32_t x = 0u; x = I2CFIFODataGetNonBlocking(I2C0_BASE, buffer); uint32_t y = x; } void initSMBus(void) { GPIOPinConfigure(GPIO_PB2_I2C0SCL); GPIOPinConfigure(GPIO_PB3_I2C0SDA); GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); // configure SCL line GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3); // configure SDA line SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0)); I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false); I2CSlaveEnable(I2C0_BASE); I2CSlaveFIFOEnable(I2C0_BASE, I2C_SLAVE_RX_FIFO_ENABLE); I2CRxFIFOConfigSet(I2C0_BASE, I2C_FIFO_CFG_RX_SLAVE); uint8_t address = 0x12; I2CSlaveInit(I2C0_BASE, address); I2CSlaveAddressSet(I2C0_BASE, 0, address); I2CSlaveIntEnable(I2C0_BASE); I2CSlaveIntEnableEx(I2C0_BASE, I2C_SLAVE_INT_STOP); I2CIntRegister(I2C0_BASE, i2cIntHandler); }
我还将附上 AD2设置的屏幕截图。
对我的问题有什么想法吗? 我确信我的"主设备"已正确连接到开发套件。
谢谢!
扎赫·夏普