I2C communication between PIC32 and LCD

231 views Asked by At

I am trying to communicate with LCD2041 using I2C . I am using PIC32MM curiosity board . I wrote the following code on MP lab code configurator , but the status for I2c communications is stuck on I2C2_MESSAGE_PENDING . I need help on what I might have done wrong or what I am missing .

#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; 
}

The default slave address for the LCD is 0x50

1

There are 1 answers

0
fbzyx On

I had a similar error once with an pic18f and mcc. I forgot to activate the global interrups. I don't see a place where you do that in your code.