This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52840 TWIM

First try to create a TWIM driver from scratch without any DMA. Following the steps in the OPS I get mixed behavior and only the chapter with DMA generates any clock and data on the interface. Without setting Master enable bit nothing will start and there is no reference in the non DMA flow diagram. Anyhow when using Master bit I get all TXD data on the bus but not RXD.

I use Prev-DK board with SDOF Stick connected to P0.27/P0.26 at 100kHz.

This is my flow right now:

// ***** INIT *****
#define USED_I2C_BLOCK 0x40003000

output_32( USED_I2C_BLOCK+I2C_TXD_MAXCNT_REG, 2 );

// enable master mode
output_32( USED_I2C_BLOCK+I2C_ENABLE_REG, 1 );

// ***** TRANSMITT *****

// send start condition
output_32( USED_I2C_BLOCK+I2C_STARTTX_REG, 1  );

// wait for int

// write data (slave address)
output_32( USED_I2C_BLOCK+I2C_TXD_REG, (SlaveAddress<<1) );

// wait for int

// write data (register address)
output_32( USED_I2C_BLOCK+I2C_TXD_REG, RegAddr );

// wait for int

// send stop bit
output_32( USED_I2C_BLOCK+I2C_STOP_REG, 1 );

// wait for int

// ***** RECEIVE *****

output_32( USED_I2C_BLOCK+I2C_RXD_MAXCNT_REG, DataBufferSize );

// enable master mode
output_32( USED_I2C_BLOCK+I2C_ENABLE_REG, 1 );

// send start condition
output_32( USED_I2C_BLOCK+I2C_STARTRX_REG, 1 );

// wait for int

// send read slave address
output_32( USED_I2C_BLOCK+I2C_TXD_REG, (SlaveAddress<<1)+1 );

// wait for int

while ( DataBufferSize-- )
{
	if ( DataBufferSize == 0 )
	{
		// send stop bit
		output_32( USED_I2C_BLOCK+I2C_STOP_REG, 1 );
	}

	// wait for int

	// read data
	*DataByte++ = input_32( USED_I2C_BLOCK+I2C_RXD_REG );
}
Parents
  • Yes the output/input works (used for 20 years, no change ;)

    I’m not using DMA and I guess that you do not need to set the pointer to TX/RX and directly read from the TXD/RXD. Also the chapter without DMA do not describe this part.

    No the controller do not add the READ bit so I have to add it. I shift the slave address because it’s an 7-bit address.

    I will try your approach because it’s more simple then my more complex implementation. If everything are handle in hardware I do not have to do it manually that I’m currently doing now.

    If you need more info or missing defines I can add them to the thread.

  • Please see the edit in my previous answer. Also, have you tried the twi_scanner example in the SDK? It is useful for making sure that everything is wired correctly and working properly. It will also show you what address to use in your code.

Reply Children
No Data
Related