Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Interfacing EEPROM (TWI) with nRF52810

Hello, I am trying to send and recieve data with the M24C32-FMN6TP 32 Kbit (4K x 8bit) eeprom. My data are arrays with 16bit values and the datasheet says it cannot write more than 32bytes at once so I tried to test this by writing three 32byte blocks and reading them back.

The following functions are used for reading and writing over TWI:

void TwiWrite(uint16_t addr, uint16_t* array_ptr, uint8_t array_len)
{
    TwiWriteExpand(&m_twi, EEPROM_SLAVE_ADDRESS, addr, (uint8_t *)(array_ptr), sizeof(*array_ptr) * array_len , FALSE);
}

void TwiWriteExpand(nrf_drv_twi_t const * p_instance, uint8_t slv_address, uint16_t address, uint8_t const *p_data, uint8_t length, bool no_stop)
{
	uint8_t buff_pos = 2;					// Offset for address
  uint8_t buffer[EEPROM_SIZE]; 	// Size of EEPROM buffer
   
    buffer[0] = (uint8_t)(address >> 8);
    buffer[1] = (uint8_t)(address & 0xFF);

    for(int i = 0; i < length; i++)
        buffer[buff_pos++] = p_data[i];    

    nrf_drv_twi_tx(p_instance, slv_address, buffer, buff_pos, FALSE); 
	}

uint16_t TwiRead(uint16_t addr, uint16_t * pdata,  uint8_t read_len)
{
	uint16_t data;
	nrf_drv_twi_tx(&m_twi, EEPROM_SLAVE_ADDRESS, (uint8_t *)&addr, 2, TRUE);										// EEPROM address
	nrf_drv_twi_rx(&m_twi, EEPROM_SLAVE_ADDRESS, (uint8_t*)pdata, (read_len * sizeof(*pdata)));	// Receive data
	
	return data;
}

The sequence in main is:

	uint16_t valuesA[16]  = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
	uint16_t valuesB[16]  = {17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32};
	uint16_t valuesC[16]  = {33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48};
	uint16_t returnA[16] =  {0};
	uint16_t returnB[16] =  {0};
	uint16_t returnC[16] =  {0};
	
	
	TwiWrite(32, valuesA, 16);
	nrf_delay_ms(10);
	TwiWrite(64, valuesB, 16);
	nrf_delay_ms(10);
	TwiWrite(96, valuesC, 16);
	nrf_delay_ms(10);
	
	TwiRead(32 , returnA, 16);
	nrf_delay_ms(10);
	TwiRead(64 , returnB, 16);
	nrf_delay_ms(10);
	TwiRead(96 , returnC, 16);

The EEPROM during debugging (optimization level 0) does not return buffer B or C, it keeps on returning A as seen in the following video: https://youtu.be/geM4tW3MBvw

What could be going wrong here?

Parents Reply Children
No Data
Related