簡體   English   中英

PIC32 和 LCD 之間的 I2C 通信

[英]I2C communication between PIC32 and LCD

我正在嘗試使用 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 上遇到過類似的錯誤。 我忘了激活全局中斷。 我看不到您在代碼中執行此操作的地方。

I2C2_MasterWrite() 是否在總線上斷言 START 條件,還是必須通過不同的 function 調用觸發?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM