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 !
Some precision, all is actually working with the softdevice, the problem is when it's called from scheduler timer.
I found and wrote a very very ugly solution:-I create an init function, which request a value to the AD7794-I schedule a function that read the value, switch to the next one, and request it. Then just stopI read the value every 4ms+wait for slave select. This is extra quite short, if it happens.the good things are:-I can read the 6 values and send a packet every 6 of them.-I can be in power save during the wait (saving energy is important for me)the bad things are:-This is really ugly-I can't just read a selected value when I want-I can't schedule is as: "get the 6 values as fast as I can, then shout it on bluetooth", all this every n ms.-if it happens that a value arrives like 8ms after request, the chip falls into a broken state.-if I want to mix ready order, or add other sensor, it might be mind-blowing.So I'm still interested to know the official way to do it