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

NRF52 Interfacing sensor with serial through UART

I have a sensor with serial protocol of 7 bits data, even parity, 2 stop bits. I wanted to use uart library to interface with this sensor. But I couldn't find the settings to change data bits, even/odd parity or number of stop bits. Is it possible to do so with uart library? Or I have to write functions by myself to read bit by bit? Thanks

Parents
  • No. If you check the UART specs you'll see it only supports 8 bit with one parity bit (or none). I believe that's even parity but I can't see where it says so. The old nRF51 series let you supply your own parity bit, which might have helped you on writes, but the nRF52 doesn't and it wouldn't help you on reads anyway.

    So you'll have to do it another way.

  • Hi RK, I kept the nrf_delay structure and added some checking functions in start bit waiting while loop. Now I can get out of the loop if anything happens and keep the device running.

    The issue now is every now and then I see faulty numbers. The sensor output consists of 9 or 10 digits, each digit is an ASCII character with 1 start bit, 7 data bits, 1 parity bit and 2 stop bits. The faulty number usually only has one digit wrong, e.g. I have seen -8.04745, -0.84745, -0.04705, -0.0474 for reading -0.04745. Is it because of interrupts of softdevice? And the reason it only affects one digit is that there is wait period between frames anyway?

    I collected some data, usually there are 5-15 wrong numbers in every 1000 samples. I'm considering just discarding those wrong numbers. Is there any callback function of softdevice interrupt in which I can flag and discard the most recent reading?

Reply
  • Hi RK, I kept the nrf_delay structure and added some checking functions in start bit waiting while loop. Now I can get out of the loop if anything happens and keep the device running.

    The issue now is every now and then I see faulty numbers. The sensor output consists of 9 or 10 digits, each digit is an ASCII character with 1 start bit, 7 data bits, 1 parity bit and 2 stop bits. The faulty number usually only has one digit wrong, e.g. I have seen -8.04745, -0.84745, -0.04705, -0.0474 for reading -0.04745. Is it because of interrupts of softdevice? And the reason it only affects one digit is that there is wait period between frames anyway?

    I collected some data, usually there are 5-15 wrong numbers in every 1000 samples. I'm considering just discarding those wrong numbers. Is there any callback function of softdevice interrupt in which I can flag and discard the most recent reading?

Children
No Data
Related