i2c how to read and write

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

i2c how to read and write

3,866 Views
wade985136
Contributor II

Use 1837 sdk  periph_i2cm_polling  example

IDE LPCXpresso

I tried to read and write some data, and I read some information
But I don’t know how to write 3bit
E.g
Write 0x2e
Read out as 0x00
As shown below 1.png

Hope someone can help me
Thank you

static void SetupXferRecAndExecute(uint8_t devAddr,
uint8_t *txBuffPtr,
uint16_t txSize,
uint8_t *rxBuffPtr,
uint16_t rxSize)
{
/* Setup I2C transfer record */
i2cmXferRec.slaveAddr = devAddr;
i2cmXferRec.options = 0;
i2cmXferRec.status = 0;
i2cmXferRec.txSz = txSize;
i2cmXferRec.rxSz = rxSize;
i2cmXferRec.txBuff = txBuffPtr;
i2cmXferRec.rxBuff = rxBuffPtr;
Chip_I2CM_XferBlocking(LPC_I2C0, &i2cmXferRec);
}

static void WriteBoard_I2CM(int writeVal)
{
uint8_t tx_buffer[3];

/* set configuration to default value */
tx_buffer[0] = BANK_0; /* Write to Config register */
tx_buffer[1] = 0;

SetupXferRecAndExecute(SMB_ADDR, tx_buffer, 3, NULL, 0);
}


static void BANK0_read()
{
uint8_t tx_buffer[3];
uint8_t rx_buffer[3];

tx_buffer[0] = BANK_0; /* Read the Voltage across the shunt */
rx_buffer[0] = 0;
Write_BAN0();
SetupXferRecAndExecute(SMB_ADDR, tx_buffer, 1, rx_buffer, 2);
DEBUGOUT("BANK_0: 0x%02X%02X\r\n", rx_buffer[0], rx_buffer[1]);

}

0 Kudos
14 Replies

3,801 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello Wade,

I still don't understand what you mean with 3bit, but since this sometimes works and other times don't I will suggest checking the signal with an oscilloscope to discard any hardware problems.

Also, I'm not familiarized with this device so be sure the write sequence an address is doing correctly.

Let me know your findings.

Best Regards,

Alexis Andalon

0 Kudos

3,793 Views
wade985136
Contributor II

HI Alexis_A

Excuse me, how does this board enter ISP MODE?

I do not see COME ACMO in LINUX

0 Kudos

3,787 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @wade985136 ,

There are two ways to enter the ISP mode:

  • In the power-on hold low the P2_7.
  • Call the reinvoke ISP ROM API in your software.

Best Regards,
Alexis Andalon

 

0 Kudos

3,779 Views
wade985136
Contributor II

hi Alexis_A

How to modify it? ISP ROM API in your software.

Thank you

0 Kudos

3,770 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @wade985136 ,

In the following link you can find a list of example to use with the LPC18xx. In this package there's an example called flashIAP that has a list of ROM commands, the reinvoke IAP between them.

You need to also import these projects to your workspace if you want to run these examples:

Alexis_A_0-1599771812070.png

Best Regards,

Alexis Andalon

 

0 Kudos

3,681 Views
wade985136
Contributor II

hiAlexis_A

1. How do I see vcom on linux?
2. Do you want to change from uart isp mode?
3. Which version of sdk are you using in the iap mode mentioned earlier
I am using sdk 3.02 version

Thank you

Best Regards

0 Kudos

3,665 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @wade985136 ,

1. How do I see vcom on linux?

 Please try this command:

dmesg | grep tty

2. Do you want to change from uart isp mode?

I'm not understanding this question, but the usual procedure to communicate with the ISP is to send the command unlock to start the communication.


3. Which version of sdk are you using in the iap mode mentioned earlier

I'm using the SDK including in the MCUXpresso 2.20 but the one you're using the latest one should be better.

Best Regards,

Alexis Andalon

0 Kudos

3,612 Views
wade985136
Contributor II

Hello, Alexis_A

I tried many times, I still can’t change uart isp to usb isp
Can you help me, how can I modify it?

0 Kudos

3,600 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @wade985136,

Please check the Table 16. Boot mode when OTP BOOT_SRC bits are zero, this section mention the state the boot pins need to be to boot from the different available sources:

 
 
 

Screenshot 2020-10-05 154837.png

Best Regards,

Alexis Andalon

0 Kudos

3,738 Views
wade985136
Contributor II

1. Is there any tool to do FLASH update on ARM LINUX

2. When I execute the IAP SDK, after displaying the ID, no other things will be displayed. Do I need to enter other commands?

0 Kudos

3,723 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @wade985136 ,

Usually, we use the flash magic tool (link) to communicate with LPC devices in ISP mode but this is only available for windows.

Also, we have a tool called LPCScrypt (link) that can be used for this purpose.

Best Regards,

Alexis Andalon

0 Kudos

3,840 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello Wade,

I don't understand what are you trying to achieve, for what I'm understanding is that you're trying to read/write a register from other device but the device is not answering as expected, am I right?

Best Regards,

Alexis Andalon

0 Kudos

3,826 Views
wade985136
Contributor II

HI  Alexis_A 

When I tried to write 3BIT,
Sometimes it succeeds, sometimes it fails
tx_buffer [0] = 0x03;
tx_buffer [1] = 0x0C;
tx_buffer [2] = 0x30;
tx_buffer [3] = 0xC0;

thank you for your help

 

0 Kudos

3,833 Views
wade985136
Contributor II

YES

 

0 Kudos