工具/软件:TI-RTOS
我尝试在 tm4c123gh下午6点使用 smbus 进行通信。 Hrer 是我的代码。 我在 g_pucSlaveRxBuffer 中不接收。
void SMBusInitonI2C (void){
//
//为 SMBus 主设备启用外设。
//
SysCtlPeripheralEnable (SYSCTL_Periph_I2C0);
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOB);
//
//为 I2C0配置所需的引脚。
//
while (!SysCtlPeripheralReady (SYSCTL_Periph_GPIOB))
{
}
GPIOPinConfigure (GPIO_PB2_I2C0SCL);
GPIOPinConfigure (GPIO_PB3_I2C0SDA);
GPIOPinTypeI2CSCL (GPIO_PORTB_BASE、GPIO_PIN_2);
GPIOPinTypeI2C (GPIO_PORTB_BASE、GPIO_PIN_3);
//
//配置 IO 多路复用器,使 I2C0的 I2C 引脚位于 PB2/3上。
//
//
//初始化主 SMBus 端口。
//
SMBusMasterInit (&g_sMaster、I2C0_BASE、SysCtlClockGet ());
I2CIntRegister (GPIO_PORTB_BASE、SMBusMasterIntHandler);
//启用主中断。
//
SMBusMasterIntEnable (&g_sMaster);
I2CMasterEnable (I2C0_BASE);
IntMasterEnable();
}
U8_t readFromSlave (U8_t device_address、U8_t device_register){
int i;
SMBusPECEnable (&g_sMaster);
返回状态= SMBusMasterByteWordRead (&g_sMaster、device_address、device_register、g_pucSlaveRxBuffer、2);
UARTprintf ("状态:%d \r\n"、返回状态);
对于(i=0;i<2;i++){
UARTprintf ("%d \r\n"、g_pucSlaveRxBuffer[i]);
}
返回0;
}
如果有人完成了 SMBus 通信、请帮助我...