【问题标题】:I2C communication between PIC32 and LCDPIC32 和 LCD 之间的 I2C 通信
【发布时间】:2023-03-23 23:48:01
【问题描述】:

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

【问题讨论】:

  • 您将 SCL 和 SDA 设置为输入似乎很奇怪(根据 cmets)。这些不应该是输出吗? I2C2_Initialize() 是否重新配置 SCL 和 SDA 引脚?
  • 不,初始化没有,我相信你的权利,它们应该被配置为输出

标签: embedded i2c mplab pic32 mcc


【解决方案1】:

我曾经在使用 pic18f 和 mcc 时遇到过类似的错误。我忘了激活全局中断。我在你的代码中没有看到你这样做的地方。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-04
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多