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

Timer Issue With HX711 - Stopped By Vector Catch Error

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"

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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++;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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();
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi, 

    I am having a hard time understanding this section of code

    That's understandable, I would have had a hard time understanding it as well had I not written it myself. Here are a couple of hints that may help clarify what I did:

    - TIMER1 + PPI + GPIOTE generates the clock signal (PD_SCK)

    - TIMER2 is set up as counter is and incremented on the falling edge of each PD_SCK clock cycle (TIMER1 CC[1] event is connected to timer 2 task through PPI). 

    Anyway, it's usually easier to start with an example so I've integrated the driver into to our ble_app_uart example, see attached. Just extract the zip file and copy the folder to /nRF5_SDK_15.2.0_9412b96/examples/ble_peripheral, then open the project in Segger Embedded studio. Pinout is defined in hx711.c. Please let me know whether it works or not. 

     ble_app_uart_w_hx711.zip

  • Works. Thank you. The only issue I have is that when I connect through Nordic Connect and read the TX Characteristic the values show up as black question marks. Something to do with my LG Q6 not reading the character codes correctly...

  • Thanks for confirming. I didn't have the ADC to test with. Regarding the black question marks, you can use sprintf, etc to encode the data. 

  • Hello,

    is there a way in which I can run this program in Keil uvision

  • Hello, 

    Yes, it should not be a problem provided you are using the same SDK version. You can use the SES project to see which files you need to include.  

1 2 3 4 5 »