I'm trying to write a quick driver for the AD7794 on nrf51822. This works on a special SPI: the MISO line is alse the "data ready" line.So when I want to read a value, I need first to ask to read the right channel, then to wait for a value, and at last to read value itself. This is not so easy with the spi_master library, but I dealed with it... out of the softdevice section.this it my function:
int read_data(int address)
//configure the reading
//use manual slave select, and set it low
//configure the channel, and ast for single read
//set the MOSI line up
//set the MISO line as input
nrf_gpio_cfg_input(BSP_SPI_SD0, NRF_GPIO_PIN_NOPULL );
//wait fot the line to be down (! ! ! )
//MISO and MOSI back to norma
//read the value
//set the CS back to high
this is what it looks like:
The problem is when I'm using the softdevice, I'm locked into the "while GPIO not 0" loop. The MISO line still works fine and go down (but so not read correctly by the app). Afer few mode ms, the MISO line get crazy, and afer a long while (1 or 2 sec), the chip reboot.I tried many things such as add delay in the loop, add app_sched_execute() in it as I thought it might get bored waiting(stupid, I know), etc... but I don't find a solution, even a bad one.
Does someone has any idea? thanks a lot !
Hi, sorry for the late response. Vacation time.. What if you do it like this:
Then in the GPIOTE event handler:
This will also be a more power efficient solution as the CPU is running in a while loop, and is not blocking other things from running.
thanks for your answer.I can do this but I must split my function at least into 2 parts. I don't like it.look this is want to be able to do:
If you want to wait quietly for something, the way to do it is to exit the function, return to idle, and wait for an interrupt. This interrupt could be the GPIOTE telling you SPI driver that data is ready, or an app_timer continuously polling the SPI lines. Blocking the main thread waiting in a for loop is generally not a good idea, so why it asserts is hard to say, it would require some debugging to know exactly why it fails.
If these sensor readings are something you do continuously, I would suggest to use the app_timer to trigger the reading instead of the scheduler. Also if the time it takes for the MISO line to go low after the command has been issued is somewhat deterministic (i.e. you can say that it is always less than 12ms) maybe it's better to hard code the waiting time using the app_timer and initiate a read sequence in the app_timer timeout interrupt.
Hi,The function is called by a app_timer (from app_timer_create), depending of the state of the bluetooth state machine(if connected, timer is on fast, if off, it's on slow). So the main tread, on the main loop just check the scheduler and low power the module.
For now, I use the timeout of the timer as interrupt, but the reading rate is just ok (5ms/measure so 33Hz). On every scheduler I ever met, there was a function "delay" and "wait_for_event", and even on linux, there is mutexs, and and non-crashing "sleep" function for threads. That's all what I want :-Or a way to create and wait for an event-Or a way to wait for some specific time, but without limit but max value of an integer. -Or bothAnd if they don't exist:-whats the limit of time, for a function called on a timer, without any hulk risk, and why, and how to change it, if it's possible?