Hi I trying to connect Altimeter ( mpl 3115a2) to the nrf52 development kit. Can someone guide me how to do it (pin connection). I have followed the example given in the sdk but still I am a little unclear. Thank you.
Hi I trying to connect Altimeter ( mpl 3115a2) to the nrf52 development kit. Can someone guide me how to do it (pin connection). I have followed the example given in the sdk but still I am a little unclear. Thank you.
In the twi_master_with_twis_slave example the pins and twi/s instances are defined in the file config.h:
#define TWI_SCL_M 3 //!< Master SCL pin
#define TWI_SDA_M 4 //!< Master SDA pin
#define MASTER_TWI_INST 0 //!< TWI interface used as a master accessing EEPROM memory
The macros are used in twi_master_init():
const nrf_drv_twi_config_t config =
{
.scl = TWI_SCL_M,
.sda = TWI_SDA_M,
...
So in the example you can change TWI_SCL_M and TWI_SDA_M to be 27 and 26 respectively to match your circuit.
The simulated EEPROM (slave) address is also defined in config.h:
#define EEPROM_SIM_ADDR 0x50 //!< Simulated EEPROM TWI address
and the address is used like so:
static ret_code_t eeprom_read(size_t addr, uint8_t * pdata, size_t size)
{
...
ret = nrf_drv_twi_tx(&m_twi_master, EEPROM_SIM_ADDR, &addr8, 1, true);
...
ret = nrf_drv_twi_rx(&m_twi_master, EEPROM_SIM_ADDR, pdata, size, false);
...
}
So EEPROM_SIM_ADDR above would in your altimeter's case be changed to 0xC0 (datasheet p.6. ; 7bit address 0x60 << 1). Otherwise the reads and writes are done similarly to how they're done in the example.
As for the read/write (register) addresses, you need to follow e.g. the sequence in MPL3115A2 datasheet p.10. IIC_RegWrite/Read are analogous to eeprom_write/read in the example (size=1).
I hope I managed to answer your question and didn't just blabber something... :)
Your read_reg() returns the unitialized ret
, not the actual register value.
Poll the STATUS register until it is 1 and then do the reading. Currently you read the register once and it's too early for the data to be ready.
So you should have something like
// reads a single 8-bit register and returns its value
static uint8_t read_reg( uint8_t slave_address, uint8_t register_address) {
uint8_t buff;
nrf_drv_twi_tx(&m_twi_master, slave_address, ®ister_address, 1, true);
nrf_drv_twi_rx(&m_twi_master, slave_address, &buff, 1, false);
return buff;
}
and
// initialization, activation
// read the status register until PTDR is set
while( !(read_reg(0x60, 0x00) & 0x08) );
// data should be ready when we get out of the while loop
// read_reg() and print
Your read_reg() returns the unitialized ret
, not the actual register value.
Poll the STATUS register until it is 1 and then do the reading. Currently you read the register once and it's too early for the data to be ready.
So you should have something like
// reads a single 8-bit register and returns its value
static uint8_t read_reg( uint8_t slave_address, uint8_t register_address) {
uint8_t buff;
nrf_drv_twi_tx(&m_twi_master, slave_address, ®ister_address, 1, true);
nrf_drv_twi_rx(&m_twi_master, slave_address, &buff, 1, false);
return buff;
}
and
// initialization, activation
// read the status register until PTDR is set
while( !(read_reg(0x60, 0x00) & 0x08) );
// data should be ready when we get out of the while loop
// read_reg() and print