10 posts / 0 new
Last post
sjabir2004@yahoo.com
Offline
Last seen:5 years 4 months ago
Joined:2015-09-18 22:13
multiple byte read i2c

Hello,
My i2c 24bit ADC sensor requires the following:
1- slv-adrs-->command_start_conversion
2- slv-adrs-->read_byte1(master ACK read)-->Read_byte2(master ACK read)- Read_byte3(master-ACK read)

How can this be done ?

问题是,ADC发送冷杉t byte and gets know ACK from the 14580 so it stops sending.

After sending address+read command , The 14580 should send an ACK after each received byte.
The attached image shows how the sensor is acknowledging the receipt of the address and starts to send the first byte
and the DA14580 is not sending ACK at the end.

Keywords:
Attachment:
Device:
MT_dialog
Offline
Last seen:2 months 4 weeks ago
Staff
Joined:2015-06-08 11:34
Hi sjabir2004,

Hi sjabir2004,

I suppose that you can achieve this functionallity with the allready exitsing i2c_eeprom_read_data() function. Just comment out the i2c_wait_until_eeprom_ready() and try to initilaize the eeprom with eeprom_init() then invoke the i2c_eeprom_read_data(data, address, num) and finally release the i2c. In the num parameter plave that you want your module to perform 3 read transactions and the da should ACK the first 2 bytes and NAK the third byte in order to finish the transaction.

Thanks MT_dialog

sjabir2004@yahoo.com
Offline
Last seen:5 years 4 months ago
Joined:2015-09-18 22:13
Hello,

Hello,

The function i2c_eeprom_read_data() will invoke read_data_single function. This function will send to the sensor , as many read signals as requested in the call BEFORE to start reading.
I do not see this functionality in my sensor. I see a stream of successive bytes sent from the sensor as in the attached document.

Here is the read_data_single function :

static void read_data_single(uint8_t **p, uint32_t address, uint32_t size)
{
int j;

i2c_send_address(address);

// this function sends successive reads while sensor needs one read only !!
for (j = 0; j < size; j++)
{
WAIT_WHILE_I2C_FIFO_IS_FULL(); // Wait if Tx FIFO is full
SEND_I2C_COMMAND(0x0100); // Set read access for times
}

// Critical section
GLOBAL_INT_DISABLE();

// Get the received data
for (j = 0; j < size; j++)
{
WAIT_FOR_RECEIVED_BYTE(); // Wait for received data
**p =(0xFF & GetWord16(I2C_DATA_CMD_REG)); // Get the received byte
(*p)++;
}
// End of critical section
GLOBAL_INT_RESTORE();
}

Attachment:
MT_dialog
Offline
Last seen:2 months 4 weeks ago
Staff
Joined:2015-06-08 11:34
Hi sjabir2004,

Hi sjabir2004,

You also directly use the read_data_single() function as long as you keep the bytes read under 32bytes. It isn't clear on your previous post though what is your problem since you state that your sensor gets the ack from the da and then stops sending and at the end of your post you say that the da doesn't send an ack at all.I ve tested on a i2c sensor with the read_data_single function and i get the ack bytes properly. The attached image is the function of the read_data_single() function and it has the same sequenceas your sensor requires.

Thanks MT_dialog

sjabir2004@yahoo.com
Offline
Last seen:5 years 4 months ago
Joined:2015-09-18 22:13
你好,

你好,

My Summary:
When I send a known command to the sensor , I get ACK from the sensor .
When I send read command to the sensor, the command is acknowledged by the sensor and the sensor starts to send three successive bytes. ( because it is 24bit)
The first byte is not Acknowledged by DA so it stops sending though I can see the sent data in the DATA_CMD_REG.

The question:
How does the DA know how many bytes to collect? (in your sent image , I noticed you wrote 3 to the sensor and collected three bytes)
When is the DA generating ACK? is it after each read byte from DATA_CMD_REG?

How does the DA14580 generate ACK?

MT_dialog
Offline
Last seen:2 months 4 weeks ago
Staff
Joined:2015-06-08 11:34
Hi sjabir2004,

Hi sjabir2004,

The da know how many bytes to collect since it performs 3 read operations. In the read_data_single in the first for loop it issues size (3) read commands so it expects 3 bytes and then it accesses the FIFO to take the bytes received. The ACK should be sent as soon as the master gets a byte in his buffer.

Thanks MT_dialog

sjabir2004@yahoo.com
Offline
Last seen:5 years 4 months ago
Joined:2015-09-18 22:13
Hello,

Hello,

这正是我说的,在t的pdfhe sensor I sent ( here attached again) , there is ONLY ONE (address+read signal) then three collected byte with ACK from DA.

The problem is that the first byte is in the buffer ( I do collect it) but there is no ACK from DA which stops the sensor transmission.

MT_dialog
Offline
Last seen:2 months 4 weeks ago
Staff
Joined:2015-06-08 11:34
Hi sjabir2004,

Hi sjabir2004,

After the first transaction you get a NACK although you are instructing your da to perform 3 succesive reads ?Do you have a logic analyser trace to attach ?

Thanks MT_dialog

daniel7043
Offline
Last seen:3 years 9 months ago
Joined:2016-01-12 14:59
Hello,

Hello,

it seems that I have got a similar problem:
I want to read some bytes from an eeprom. How to get the data shows the picture in the attachment.
But as sjabir I have the problem that I can just receive the first byte, because my DA14580 sends a NACK, so the eeprom stops to sends the other bytes.
Here is my code:

GLOBAL_INT_DISABLE();
int a = 0;
uint8_t value[16] = {0};
i2c_eeprom_init(I2C_SLAVE_ADDRESS, I2C_SPEED_MODE, I2C_ADDRESS_MODE, I2C_ADDRESS_SIZE);
SEND_I2C_COMMAND(02); //1. u 2.
WAIT_WHILE_I2C_FIFO_IS_FULL();
SEND_I2C_COMMAND(0x0100);

for(int i = 0;i<16;i++)
{
WAIT_FOR_RECEIVED_BYTE(); // Wait for received data
value[i] =(0xFF & GetWord16(I2C_DATA_CMD_REG)); // Get the received byte
}
GLOBAL_INT_RESTORE();
}

It wont go further than WAIT_FOR_RECEIVED_BYTE() (after the first byte was send).

I also attached the picture from my anaylizer.

I am grateful for any help!

Daniel

Attachment:
daniel7043
Offline
Last seen:3 years 9 months ago
Joined:2016-01-12 14:59
I found my own mistake...

I found my own mistake...
I changed the line

WAIT_WHILE_I2C_FIFO_IS_FULL();
SEND_I2C_COMMAND(0x0100);

to

for(int i = 0;i<16;i++)
{
WAIT_WHILE_I2C_FIFO_IS_FULL();
SEND_I2C_COMMAND(0x0100);
}

Topic locked