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.

  • I mean if there is certain type of softdevice interrupt taking long time, I can discard data when it happens. I don't see wrong numbers a lot, I assume it doesn't happen quite often. If this is not possible, I cannot tell whether the reading is real measurement or contains wrong bit because of UART transmission.

    I have never used timeslot API, it looks like it's only good for period of 100~125 us? My data transmission takes ~20 ms though.

    You mentioned using timer interrupt earlier.

    1. I remember app timer has resolution of about 30 us. How could I get a timer with higher resolution?
    2. Another issue I could anticipate is the wait time between stop bits and the next start bit is not consistent. That means I can't keep the timer on I have to start the timer when start bit is detected and stop it after I read 7 data bits. Is it possible?
    3. Do I change timer priority in app_timer.c?
Reply
  • I mean if there is certain type of softdevice interrupt taking long time, I can discard data when it happens. I don't see wrong numbers a lot, I assume it doesn't happen quite often. If this is not possible, I cannot tell whether the reading is real measurement or contains wrong bit because of UART transmission.

    I have never used timeslot API, it looks like it's only good for period of 100~125 us? My data transmission takes ~20 ms though.

    You mentioned using timer interrupt earlier.

    1. I remember app timer has resolution of about 30 us. How could I get a timer with higher resolution?
    2. Another issue I could anticipate is the wait time between stop bits and the next start bit is not consistent. That means I can't keep the timer on I have to start the timer when start bit is detected and stop it after I read 7 data bits. Is it possible?
    3. Do I change timer priority in app_timer.c?
Children
No Data
Related