nrf5/hal: Adding untested implementation of twi read. Lacking sensors to test with :)

This commit is contained in:
Glenn Ruben Bakke 2017-03-04 21:42:36 +01:00
parent 4a631a0d47
commit 2c61b7f596
2 changed files with 32 additions and 2 deletions

View File

@ -93,8 +93,37 @@ void hal_twi_master_tx(NRF_TWI_Type * p_instance,
void hal_twi_master_rx(NRF_TWI_Type * p_instance,
uint8_t addr,
uint16_t transfer_size,
const uint8_t * rx_data) {
uint8_t * rx_data,
bool stop) {
uint16_t number_of_rxd_bytes = 0;
p_instance->ADDRESS = addr;
p_instance->EVENTS_RXDREADY = 0;
p_instance->TASKS_STARTRX = 1;
while (number_of_rxd_bytes < transfer_size) {
// wait for the transaction complete
while (p_instance->EVENTS_RXDREADY == 0) {
;
}
rx_data[number_of_rxd_bytes] = p_instance->RXD;
p_instance->EVENTS_RXDREADY = 0;
number_of_rxd_bytes++;
}
if (stop) {
p_instance->EVENTS_STOPPED = 0;
p_instance->TASKS_STOP = 1;
while (p_instance->EVENTS_STOPPED == 0) {
;
}
}
}
void hal_twi_slave_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) {

View File

@ -108,7 +108,8 @@ void hal_twi_master_tx(NRF_TWI_Type * p_instance,
void hal_twi_master_rx(NRF_TWI_Type * p_instance,
uint8_t addr,
uint16_t transfer_size,
const uint8_t * rx_data);
uint8_t * rx_data,
bool stop);
void hal_twi_slave_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init);