Part Number: PROCESSOR-SDK-AM62X
Hi,
I would like to test the i2c read and write using EEPROM on AM62x-EVM.
But I was not able write using the following.
Here is the code that i am trying.
/*
* Copyright 2006-2009 Freescale Semiconductor, Inc. All rights reserved.
*/
/*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include "mxc_test.h"
int main(int argc, char **argv)
{
i2c_test i2c_test;
int i2c_file;
char reg[1];
char buf[2];
int fail = 0;
printf("\nTest: I2C Test With EEPROM!\n");
i2c_file = open("/dev/i2c-0", O_RDWR);
if (i2c_file < 0) {
printf("Open failed\n");
exit(-1);
}
/* Enable the CSI clock */
ioctl(i2c_file, 3, &i2c_test);
i2c_test.bus = 0;
i2c_test.slave_addr = 0x51;
printf("Slave address=0x%x\n\n", i2c_test.slave_addr);
reg[0] = 0x00;
buf[1] = 0x4;
buf[0] = 0x0;
i2c_test.reg = reg;
i2c_test.reg_size = 1;
i2c_test.buf = buf;
i2c_test.buf_size = 2;
printf("Data write: buf[0]=%x, buf[1]=%x to reg=%x\n", buf[0], buf[1], reg[0]);
ioctl(i2c_file, 2, &i2c_test);
buf[0] = 0;
buf[1] = 0;
i2c_test.buf = buf;
ioctl(i2c_file, 1, &i2c_test);
if (i2c_test.buf[0] != 0x0) {
fail = 1;
}
if ((i2c_test.buf[1] & 0x4)!= 0x4) {
fail = 1;
}
printf("Data read: buf[0]=%x, buf[1]=%x from reg=%x\n", buf[0], buf[1], reg[0]);
if (fail == 1) {
printf("\nI2C TEST FAILED\n\n");
} else {
printf("\nI2C TEST PASSED\n\n");
}
/* Disable the CSI clock */
ioctl(i2c_file, 4, &i2c_test);
close(i2c_file);
return 0;
}
But as you can see here, it is not working.
Test: I2C Test With EEPROM! Slave address=0x51 Data write: buf[0]=0, buf[1]=4 to reg=0 Data read: buf[0]=0, buf[1]=0 from reg=0 I2C TEST FAILED
And this is the dts file. I configured the pin 21 and 24 of J9(MCU header pins) and pin 27 and 28 of J3(IO expansion pins).
Bus number is 0 and address is 0x51.
10a11
> serial5 = &main_uart5;
23c24
< bootargs = "console=ttyS2,115200n8 earlycon=ns16550a,mmio32,0x02800000";
---
> bootargs = "console=ttyS2,115200n8 earlycon=ns16550a,mmio32,0x02850000";
231a233,246
> led1 {
> compatible = "gpio-leds";
> pinctrl-names = "default";
> pinctrl-0 = <&usr_led_pins_test>;
>
> led-0 {
> label = "test";
> gpios = <&main_gpio0 42 GPIO_ACTIVE_HIGH>;
> linux,default-trigger = "heartbeat";
> function = LED_FUNCTION_HEARTBEAT;
> default-state = "on";
> };
> };
>
257a273,280
> main_uart5_pins_default: main-uart5-pins-default {
> pinctrl-single,pins = <
> AM62X_IOPAD(0x1d8, PIN_INPUT, 1) /* (C15) MCAN0_TX.UART5_RXD */
> AM62X_IOPAD(0x1dc, PIN_OUTPUT, 1) /* (E15) MCAN0_RX.UART5_TXD */
> >;
> };
>
> // this is connected to EEPROM
335a359,364
> usr_led_pins_test: usr-led-pins-test {
> pinctrl-single,pins = <
> AM62X_IOPAD(0x00ac, PIN_OUTPUT, 7) /* (L21) GPMC0_CSn1.GPIO0_42 */
> >;
> };
>
453a483,491
> &mcu_pmx0 {
> mymcui2c1_pins_default: mymcui2c1-pins-default {
> pinctrl-single,pins = <
> AM62X_MCU_IOPAD(0x0044, PIN_INPUT, 0) /* (A8) MCU_I2C0_SCL */
> AM62X_MCU_IOPAD(0x0048, PIN_INPUT, 0) /* (D10) MCU_I2C0_SDA */
> >;
> };
> };
>
486c524,525
< status = "disabled";
---
> pinctrl-names = "default";
> pinctrl-0 = <&main_uart5_pins_default>;
And this is from dtsi file. (no changes was made to this)
&main_i2c0 {
pinctrl-names = "default";
pinctrl-0 = <&main_i2c0_pins_default>;
clock-frequency = <400000>;
typec_pd: usb-pd@3f {
compatible = "ti,tps6598x";
reg = <0x3f>;
connector {
ports {
#address-cells = <1>;
#size-cells = <0>;
port@1 {
reg = <1>;
usb_con_hs: endpoint {
remote-endpoint = <&typec_hs>;
};
};
};
};
};
};
// this is connected to EEPROM
main_i2c0_pins_default: main-i2c0-pins-default {
pinctrl-single,pins = <
AM62X_IOPAD(0x1e0, PIN_INPUT_PULLUP, 0) /* (B16) I2C0_SCL */
AM62X_IOPAD(0x1e4, PIN_INPUT_PULLUP, 0) /* (A16) I2C0_SDA */
>;
};