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.
Thanks, this was really helpful. Just one more doubt, so i will have to use nrf_drv_twi_tx to write to the register right ?
Yes with nrf_drv_twi_tx you write. First the register address, then the data. Like in the eeprom_write example function, something like
uint8_t target_register = 0x26;
nrf_drv_twi_tx(&m_twi_master, ALTIMETER_ADDRESS, &target_register, 1, true);
uint8_t data_to_write = 0xB8;
size_t size = sizeof(data_to_write);
nrf_drv_twi_tx(&m_twi_master, ALTIMETER_ADDRESS, &data_to_write, size, false);
I wrote two functions to read and write register as follows:
//Read and write register
static ret_code_t write_reg( uint8_t slave_address, uint8_t target_register, uint8_t data_to_write) {
ret_code_t ret;
nrf_drv_twi_tx(&m_twi_master, slave_address, &target_register, 1, true);
size_t size = sizeof(data_to_write);
nrf_drv_twi_tx(&m_twi_master, slave_address, &data_to_write, size, false);
return ret;
}
static ret_code_t read_reg( uint8_t slave_address, uint8_t register_address) {
ret_code_t ret;
uint8_t buff[IN_LINE_PRINT_CNT];
nrf_drv_twi_tx(&m_twi_master, slave_address, ®ister_address, 1, true);
nrf_drv_twi_rx(&m_twi_master, slave_address, buff, IN_LINE_PRINT_CNT, false);
return ret;
}
Then according to the datasheet I did the following:
/*Set Altimeter with an OSR = 128 */
write_reg(0x60, 0x26, 0xB8);
/*Enable Data Flags in PT_DATA_CFG*/
write_reg(0X60, 0x13 , 0x07);
/*By Polling*/
/* Set Active*/
write_reg(0x60, 0x26, 0xB9);
/* Read Status register*/
int STA = read_reg(0x60, 0x00);
while ( (STA & 0x08) == 1) {
int OUT_P_MSB = read_reg(0x60, 0x01);
int OUT_P_CSB = read_reg(0x60, 0x02);
int OUT_P_LSB = read_reg(0x60, 0x03);
int OUT_T_MSB = read_reg(0x60, 0x04);
int OUT_T_LSB = read_reg(0x60, 0x05);
printf(" Raw data %d, %d, %d, %d, %d", OUT_P_MSB, OUT_P_CSB, OUT_P_LSB, OUT_T_MSB, OUT_T_LSB);
}
But still I am not getting any output. But if I use it with the do_print_data and put the EEPROM_SIM_ADDR as 0x60 I get some random address but with 0xC0 I do not get any output. Any idea why?
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
Hi,
i usea nrf52835, why you say that the pin of SDA are P0.26 and P 0.27? Form product specification i read that the pin SWDCLCK and SWDIO are 26 and 25. What is the different?
Thanks, Anna