TucsonDon
Member
I am having issues with the i2c protocol that I hope someone can help with. I am using a PIC18F46K22 as a master. I am also using MCC for the code and have attached copies of the files that it generated and a shot of my logic analyzer that shows the output. That output is for a lcd display (address 0x50) which if I read it right it is acknowledging the address but that is it, no data transfer and nothing on the display. I also have tried MCU-MCU (master to slave) with the same result.
I have tried to step through the code in MPLab over and over but I am unable to identify the problem
header file
I have tried to step through the code in MPLab over and over but I am unable to identify the problem
C:
uint8_t data;
uint8_t addr;
/******************************************************************************/
static void display_write (uint8_t addr, uint8_t data);
static uint16_t temp_read (uint8_t addr);
/******************************************************************************/
static void display_write (uint8_t addr, uint8_t data)
{
i2c_write1ByteRegister(LCD, addr, data);
__delay_ms(5);
}
static uint16_t temp_read (uint8_t addr)
{
return i2c_read2ByteRegister (TEMP, addr);
}
/*****DISPLAY COMMANDS*********************************************************/
void display_Initialize (void)
{
display_write (Display_on, NULL);
display_write (Clear_screen, NULL);
display_write (Cursor_home, NULL);
}
void display_add (ddadr)
{
display_write (Set_cursor, ddadr);
}
void clear_display (void)
{
display_write (Clear_screen, NULL);
}
void putsLCD (char *buffer)
{
while(*buffer) // Write data to LCD up to null
{
display_write (NULL, *buffer); // Write character to LCD
buffer++; // Increment buffer
}
return;
}
/*****TEMPERATURE**************************************************************/
i2c_temp Get_Temp (void)
{
RawTemp.RawPool = temp_read (Pool);
RawTemp.RawSolar = temp_read (Solar);
RawTemp.RawWater = temp_read (Water);
}
header file
C:
#ifndef I2C_LCD_H
#define I2C_LCD_H
#include "temp.h"
#define LCD 0x50 //LCD I2C Address
/************LCD Display Commands*************************************************/
#define Display_on 0x41 //turns the display on
#define Display_off 0x42 //turn the display off
#define Set_cursor 0x45 //move to address
#define Cursor_home 0x46 //moves to address 0,0
#define Underline_on 0x47 //turns underline cursor on
#define Underline_off 0x48 //turns underline cursor off
#define Cursor_left 0x49 //shifts cursor left one space
#define Cursor_right 0x4A //shifts cursor righr one space
#define Blink_on 0x4B //turns on blinking cursor
#define Blink_off 0x4C //turns off blinking cursor
#define Backspace 0x4E //moves cursor back one space
#define Clear_screen 0x51 //clears the screen
#define Set_contrast 0x52 //sets screen contrast (1-50)
#define Set_brightness 0x53 //sets screen brightness (1-8)
#define Load_character 0x54 //loads custom character
#define Display_left 0x55 //shifts display left one space
#define Display_right 0x56 //shifts display right onr space
#define Change_addr 0x62 //changes display i2c address
#define Display_firmware 0x70 //displays firmware ver
#define Display_addr 0x72 //displays i2c address
/*****FUNCTION PROTOTYPE*******************************************************/
void display_Initialize (void);
void clear_display (void);
void putsLCD (char *buffer);
i2c_temp Get_Temp (void);
void display_add ();
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* I2C_LCD_H */
Attachments
Last edited: