Hello,
I have a 1602A V2.0 LCD display (16 chars x 2 lines) that I intend to connect to my MK26 ARM M4 MCU via a LCM 1602 I2C extender (which has a Philips PCF8574AT on it).
I'm trying to get it to work since this morning, but apparently, the address I calculated for the I2C extender (0x3F according to this datasheet, A0, A1, A2 are non-jumpered) is not OK, so I tried to scan for a valid address where the I2C extender would ACK me back, but I cannot find any.
I connected just the PCF8574AT to my board, the LCD is not connected and it still doesn't work.
I have the following piece of code (KSDK 2.0):
#include "fsl_gpio.h"
#include "fsl_port.h"
#include "fsl_i2c.h"
#include "Retarget.h"
#include "Log.h"
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
int main()
{
RetargetInit();
i2c_master_config_t masterConfig;
uint8_t status;
/* Get default configuration for master. */
I2C_MasterGetDefaultConfig(&masterConfig);
printf("Got def. config\r\n");
/* Init I2C master. */
I2C_MasterInit(I2C0, &masterConfig, CLOCK_GetFreq(I2C0_CLK_SRC));
//I2C_Enable()
printf("Init\r\n");
/* Send start and slave address. */
printf("Starting...\r\n");
// 0x70, 0x27, 0x38, 0x20, 0x3F
uint8_t u8Addr = 0x3F;
for(u8Addr=0; u8Addr<128; u8Addr++)
{
status = I2C_MasterStart(I2C0, u8Addr, kI2C_Write);
LOG("sent address 0x%x", u8Addr);
uint32_t u32Flags;
/* Wait address sent out. */
uint16_t timeout = UINT16_MAX;
while(!((u32Flags = I2C_MasterGetStatusFlags(I2C0)) & kI2C_IntPendingFlag) && (--timeout))
{
}
if((u32Flags = I2C_MasterGetStatusFlags(I2C0)) & kI2C_IntPendingFlag)
{
LOG("ADDRESSS 0x%x IS OK", u8Addr);
}
LOG("timeout is %d", timeout);
//LOG("done address");
status = I2C_MasterStop(I2C0);
LOG("Stopped with status=%d", status);
}
}
Could you please point out what I'm doing wrong, why my scan doesn't yield any results?
Or is there a problem with my I2C extender, phisycally?
I'd expect the output of the above code to contain a single "ADDRESSS 0x... IS OK" line with a timeout different than 0, but that's not the case.
Merry Christmas!
Hi Paul,
See Creating an i2c address scanner .
I'm using a Processor Expert component for this which provides the ScanDevice() which probes a device on the bus:
As you are using the SDK, that approach does not work directly for you. But you could have a look at the code in the McuEclipseLib project on GitHub (McuOnEclipseLibrary/lib/src at master · ErichStyger/McuOnEclipseLibrary · GitHub ) and the McuGenericI2C ScanDevice() function. That function gets called form the command line parser (ParseCommand() in I2CSpy, you can see how this would look like in CSI Crime Scene Investigation with I2CSpy and Freedom Board | MCU on Eclipse .
Other than that: make sure you are configuring the I2C clocks correctly: there is a silicon errata for this (see KL25Z and I2C: Missing Repeated Start Condition | MCU on Eclipse ).
I hope this helps, and Merry Christmas!
Erich