DEBUG模式没出现状态码0x18,直接就0x20了。。。
然后我看了你们官方的例子也没用那个库函数的,于是找到了采用分立函数的
- void OLED_Write_cmd(uint8_t cmd)
- {
- // HAL_I2C_Mem_Write(&hi2c2, 0x78, 0x00, I2C_MEMADD_SIZE_8BIT, &cmd, 1, 0x100);
- /* Send START */
- I2C_START(I2C0);
- I2C_WAIT_READY(I2C0);
- /* Send device address */
- I2C_SET_DATA(I2C0, 0x78);
- I2C_SET_CONTROL_REG(I2C0, I2C_CTL_SI);
- I2C_WAIT_READY(I2C0);
- /* Send register number and MSB of data */
- I2C_SET_DATA(I2C0, 0x00);
- I2C_SET_CONTROL_REG(I2C0, I2C_CTL_SI);
- I2C_WAIT_READY(I2C0);
- /* Send data */
- I2C_SET_DATA(I2C0, cmd);
- I2C_SET_CONTROL_REG(I2C0, I2C_CTL_SI);
- I2C_WAIT_READY(I2C0);
- /* Send STOP */
- I2C_STOP(I2C0);
-
-
- }
- void OLED_Write_data(uint8_t data)
- {
- // HAL_I2C_Mem_Write(&hi2c2, 0x78, 0x40, I2C_MEMADD_SIZE_8BIT, &data, 1, 0x100);
- /* Send START */
- I2C_START(I2C0);
- I2C_WAIT_READY(I2C0);
- /* Send device address */
- I2C_SET_DATA(I2C0, 0x78);
- I2C_SET_CONTROL_REG(I2C0, I2C_CTL_SI);
- I2C_WAIT_READY(I2C0);
- /* Send register number and MSB of data */
- I2C_SET_DATA(I2C0, 0x40);
- I2C_SET_CONTROL_REG(I2C0, I2C_CTL_SI);
- I2C_WAIT_READY(I2C0);
-
- /* Send data */
- I2C_SET_DATA(I2C0, data);
- I2C_SET_CONTROL_REG(I2C0, I2C_CTL_SI);
- I2C_WAIT_READY(I2C0);
- /* Send STOP */
- I2C_STOP(I2C0);
-
- }
复制代码 实现如上,竟然可以驱动了。奇了怪了。。。经过调试状态码出现了0x18,正常通信了,见鬼了。。。我要好好分析一下你们那个不能用的库函数到底哪儿的问题
|