cancel
Showing results for 
Search instead for 
Did you mean: 

using the st25dv04k i2c address

HKhan.4
Associate II

Hello 

We have built a custom board using the st25dv04k and are having trouble understanding how to use it. The device communication is using i2c and the started address we are always using is 0.

The functions we are using are simple read and write functions:

static inline int i2c_write(const struct device *dev, const uint8_t *buf, uint32_t num_bytes, uint16_t addr)

Write a set amount of data to an I2C device. This routine writes a set amount of data synchronously.

Parameters:

dev

 – Pointer to the device structure for an I2C controller driver configured in controller mode.

buf

 – Memory pool from which the data is transferred.

num_bytes

 – Number of bytes to write.

addr

 – Address to the target I2C device for writing.

Return values:

0 If successful.

-EIO General input / output error.

static inline int i2c_read(const struct device *dev, uint8_t *buf, uint32_t num_bytes, uint16_t addr)

Read a set amount of data from an I2C device. This routine reads a set amount of data synchronously.

Parameters:

dev

 – Pointer to the device structure for an I2C controller driver configured in controller mode.

buf

 – Memory pool that stores the retrieved data.

num_bytes

 – Number of bytes to read.

addr

 – Address of the I2C device being read.

Return values:

0 If successful.

-EIO General input / output error.

The start and and stop conditions are included in the functions. We are firstly just trying to confirm that the board configurations are correct and are looking for a way to do so and not receive strange values. Please assist in a way to help us confirm that they are correct. If possible, please include what to put in the buffer and what to put in the device i2c address. Thank you in advance!

Kind regards,

Hassan

1 ACCEPTED SOLUTION

Accepted Solutions
JL. Lebon
ST Employee

Hello,

In your functions I think you are missing a parameter.

"addr

 – Address of the I2C device being read."

You actually need two different addresses to access the memory of the device.

The first Byte sent to the ST25DV04K is the device address (A6h or 53h as mentioned before). This always has to be the first Byte and it selects the ST25DV04K.

Then, for a write, it has to be followed by a 2 Bytes memory address. This is the memory pointer inside the St25DV04K that need to be set. Then, after those 3 bytes (device address + Memory address) you can send your data o be written.

For a read, it is a bit more complex. You have to first set the memory address pointer like a write command, and then do a start again and send the device address again and then read data.

I2C write command looks like:

START/device address/W/ACK/Memory address MSB/ACK/Memory address LSB/ACK/data/ACK/data/ACK .../STOP

I2C read command looks like:

START/device address/W/ACK/Memory address MSB/ACK/Memory address LSB/ACK/START/device address/R/ACK/data read/ack/dataread.../Nack/STOP

Best regards.

View solution in original post

3 REPLIES 3
Ulysses HERNIOSUS
ST Employee

Hi,

please see the data sheet chapter 6.3 (Device addressing). For addressing user mode I expect you will need to use address A6h or 53h (depending how your i2c function interprets the address (including or not including the direction bit).

Regards, Ulysses

HKhan.4
Associate II

Hello,

Thank you for the assistance. Yes, I believe that the device select code is correct and when I write and read using it the request seems to be going through. I am just having trouble as i'm not sure what to do after that to confirm that it is working. The documentation is difficult to comprehend. We also have an antenna connected but we can't seem to detect it through NFC tools. I'm not quite understanding as to my understanding, the RF field should be available once st25dv04k is powered?

JL. Lebon
ST Employee

Hello,

In your functions I think you are missing a parameter.

"addr

 – Address of the I2C device being read."

You actually need two different addresses to access the memory of the device.

The first Byte sent to the ST25DV04K is the device address (A6h or 53h as mentioned before). This always has to be the first Byte and it selects the ST25DV04K.

Then, for a write, it has to be followed by a 2 Bytes memory address. This is the memory pointer inside the St25DV04K that need to be set. Then, after those 3 bytes (device address + Memory address) you can send your data o be written.

For a read, it is a bit more complex. You have to first set the memory address pointer like a write command, and then do a start again and send the device address again and then read data.

I2C write command looks like:

START/device address/W/ACK/Memory address MSB/ACK/Memory address LSB/ACK/data/ACK/data/ACK .../STOP

I2C read command looks like:

START/device address/W/ACK/Memory address MSB/ACK/Memory address LSB/ACK/START/device address/R/ACK/data read/ack/dataread.../Nack/STOP

Best regards.