I need to output a clock to measure crystal.
Though I am running in Zephyr/NC v2.3.0, I could not figure out how to configure it using high-level driver interface.
So I went with this:
void clock_out()
{
NRF_GPIO->PIN_CNF[C_OUTPIN] = 1;
NRF_GPIO->OUTSET = ( 1 << C_OUTPIN );
NRF_GPIO->OUTCLR = ( 1 << C_OUTPIN );
NRF_GPIOTE->CONFIG[3] = 0x00130003 + ( C_OUTPIN << 8 ); // Toggle + Task mode.
C_TIMER->MODE = 0;
C_TIMER->BITMODE = 3;
C_TIMER->SHORTS = 1;
C_TIMER->PRESCALER = 1;
C_TIMER->CC[0] = 8;
NRF_PPI->CH[0].EEP = C_TIMER->EVENTS_COMPARE[0];
NRF_PPI->CH[0].TEP = NRF_GPIOTE->TASKS_OUT[3];
NRF_PPI->CHENSET = 0x01;
C_TIMER->TASKS_START = 1;
C_TIMER->EVENTS_COMPARE[0] = 1;
C_TIMER->TASKS_CLEAR = 1;
}
void main(void)
{
printk( "Starting clock out route\n");
clock_out();
// dtm_loop();
NRF_GPIO->PIN_CNF[17] = 1;
while( 1 )
{
k_msleep( 1000 );
C_TIMER->TASKS_CAPTURE[1] = 1;
printk( "Timer was: %u. Compare is: %u. Evt0: %u. Evt1: %u\n",
C_TIMER->CC[1], C_TIMER->CC[0], C_TIMER->EVENTS_COMPARE[0], C_TIMER->EVENTS_COMPARE[1] );
if( NRF_GPIO->OUT & ( 1 << 17 ))
{
NRF_GPIO->OUTCLR = ( 1 << 17 );
}
else{
NRF_GPIO->OUTSET = ( 1 << 17 );
}
}
}
I can toggle the port using NRF_GPIOTE->TASK_OUT[].
From the output of the k_msleep() loop I can see that the timer is running in the expected interval up to the compare value. However EVENT_COMPARE[0] is always 1 which seems wrong.
The output pin is stuck at "1".
What could be wrong?
Initialization sequence?
Rgds Tage