Details: SDK v15.2.0 using HX711 sample code copy-pasted over twi_master_using_nrf_twi_mngr example. Windows 8.1, uploading to nRF52 DK.
I am having a hard time understanding this section of code. I read the timer section in the product specs v1.4, but I am clearly still not understanding it fully.
- When I run it in the debugger, it loops through the do-while loop in the section of code below a lot and never increments any timer1 or timer2 register values. I added the NRF_LOG_INFO((int) NRF_TIMER2->CC[1]); line to try and readout the value but it just sends LOG: "blank"
- When I build and run it on the board, it tells me "stopped by vector catch"
for (uint32_t i=0; i < ADC_RES; i++) { do { /* NRF_TIMER->CC[1] contains number of clock cycles.*/ NRF_TIMER2->TASKS_CAPTURE[1] = 1; if (NRF_TIMER2->CC[1] >= ADC_RES) goto EXIT; // Readout not in sync with PD_CLK. Abort and notify error. else { NRF_LOG_INFO((int) NRF_TIMER2->CC[1]); NRF_LOG_FLUSH(); } } while(NRF_TIMER1->EVENTS_COMPARE[0] == 0); NRF_TIMER1->EVENTS_COMPARE[0] = 0; m_sample.value |= (nrf_gpio_pin_read(DOUT) << (23 - i)); m_sample.count++; }
When I read the code above, it tells me this:
- loop through until i equals the number of ADC bits desired
- capture timer2 value to CC[1] register
- if: CC[1] (set to timer2 value) is equal or greater than ADC bits then exit (but timer2 was never started, why??)
- else: logger
- continue to do this until timer1 events_compare[0] is not zero (but CC[0] was initialised to 1, and events_compare would only go high if timer1 was equal to the value in CC[0] so unless timer1 overflows, it's unlikely it will catch??)
- reset events_compare[0]
This code was written by Vidar so I'm sure it works fine. I feel like I'm doing something wrong
My main function looks like this:
int main(void) { /* Initialise logging */ uint32_t err_code = NRF_LOG_INIT(NULL); APP_ERROR_CHECK(err_code); NRF_LOG_DEFAULT_BACKENDS_INIT(); /* Initialise hx711 */ hx711_mode_t mikes_mode; hx711_init(mikes_mode, m_evt_handler); hx711_start(false); NRF_LOG_FLUSH(); // push out message while(true) { NRF_LOG_INFO("print me"); nrf_drv_gpiote_in_event_disable(DOUT); // maybe needed hx711_sample(); // Getting caught here nrf_delay_ms(1000); NRF_LOG_FLUSH(); } }