MSP432E401YT硬件IIC驱动0.96OLED
其他内容后期补,先放视频和代码。
视频展示
MSP432E401YT硬件IIC驱动0.96OLED
主要代码
1.时钟配置和I2C1初始化配置
.
uint32_t systemClock;
/* Configure the system clock for 120 MHz */
systemClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),
120000000);
/* Enable clocks to GPIO Port G and configure pins as I2C */
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
while(!(MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOG)))
{
}
MAP_GPIOPinConfigure(GPIO_PG0_I2C1SCL);
MAP_GPIOPinConfigure(GPIO_PG1_I2C1SDA);
MAP_GPIOPinTypeI2C(GPIO_PORTG_BASE, GPIO_PIN_1);
MAP_GPIOPinTypeI2CSCL(GPIO_PORTG_BASE, GPIO_PIN_0);
// /* Since there are no board pull up's we shall enable the weak internal
// * pull up */
// GPIOG->PUR |= (GPIO_PIN_1 | GPIO_PIN_0);
/* Enable the clock to I2C-1 module and configure the I2C Master */
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
while(!(MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_I2C1)))
{
}
MAP_I2CMasterInitExpClk(I2C1_BASE, systemClock, true);//必须为TRUE
2.硬件I2C OLED写函数
.
static void OLED_WR_Byte(uint8_t dat,uint8_t mode){
/* Put the Slave Address on the bus for Write */
MAP_I2CMasterSlaveAddrSet(I2C1_BASE, SLAVE_ADDRESS>>1, false);//读写位计算进去了,函数内为7位从地址
while(MAP_I2CMasterBusy(I2C1_BASE))
{
}
/* Write the first byte of the command to the bus */
if(mode){
MAP_I2CMasterDataPut(I2C1_BASE, 0x40);//数据
}
else{
MAP_I2CMasterDataPut(I2C1_BASE, 0x00);//命令
}
MAP_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
/* Wait until the I2C transaction is complete. */
while(MAP_I2CMasterBusy(I2C1_BASE))
{
}
/* Send the second byte of the command to the bus */
MAP_I2CMasterDataPut(I2C1_BASE, dat);
MAP_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
/* Wait until the I2C transaction is complete. */
while(MAP_I2CMasterBusy(I2C1_BASE))
{
}
MAP_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
}
工程获取
-
CSDN积分下载地址:工程下载
-
关注微信公众号“亦呦啊哈”,回复“ 20230527 ”下载