我正在尝试使用I2C与LCD2041通信。我正在使用PIC32MM好奇心板。我在MP实验室代码配置器上写了以下代码,但I2c通信的状态一直停留在I2C2_MESSAGE_PENDING上。我需要帮助解决我可能做错了什么或我错过了什么。
#include <stdint.h>
#include <string.h>
#include <xc.h>
#include "mcc_generated_files/mcc.h"
//#include "lcd_i2c.h"
#define slave_Adress 0b01010000
void ByteDelay(void){
// Delay between bytes required by LCD2041 spec
DELAY_microseconds(625);
}
void ReadDelay(void){
// Delay between read commands required by LCD2041 spec
DELAY_milliseconds(3);
}
void TransactionDelay(void){
// Delay between transactions required by LCD2041 spec
DELAY_microseconds(375);
}
int main(void)
{
SYSTEM_Initialize();
uint8_t data = 0xFE; // host to tell data are output via I2c
uint8_t lcd_clear_display = 0xA4; // command to clear LCD
TRISBbits.TRISB2 = 1; // set B2 (scl) as input
TRISBbits.TRISB3 = 1; // set B3 (SDA) as input
I2C2_Initialize() ;
I2C2_MESSAGE_STATUS status ;
I2C2_MasterWrite(data, 1 , slave_Adress, &status);
ByteDelay();
if ( status == I2C2_MESSAGE_PENDING) {led_3_SetHigh();}
return 1;
}
LCD的默认从属地址为0x50
我曾经在pic18f和mcc中遇到过类似的错误。我忘了激活全局查询。我在代码中找不到这样做的地方。