0

我正在尝试使用 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

4

1 回答 1

0

我曾经在 pic18f 和 mcc 上遇到过类似的错误。我忘了激活全局中断。我看不到您在代码中执行此操作的地方。

于 2020-12-26T19:55:48.317 回答