Jump to content
Fourth of July -- Digilent US offices closed ×
  • 0

How to read 16bit integers using WaveForms UART Protocol


ALackOfNumbers

Question

I am trying to read 16bit integers sent to an Analog Discovery 2 over UART using the Protocol section in waveforms. The integers are sent in two bytes, 8 bit high byte then 8 bit low byte. 

When I set the RX to binary and the bits to 8, I can receive all the bytes correctly. When I set it to receive 16 bits, then errors occur because I am sending the data as two 8 bit messages.

I want to be able to set RX to decimal and have the Protocol correctly convert two 8 bit transmissions to a single 16 bit decimal integer. Is this possible? 

Note: I cannot send a full 16 bit message, my microcontroller registers are limited to sending 8 bits at a time. I only want to do this so that I do not have to manually change the pairs of 8 bit values into 16 bit decimals. 

Example:

Correct values in decimal: 2 64 128 2048

RX Binary, 8 bit:

00000000 00000010 00000000 01000000 00000000 10000000 00001000 00000000

RX Binary, 16 bit:

0000100100000000 0000000100000000 0000010000000001 0000000100001000 

RX Decimal, 8 bit: 0 0 2 0 64 0 128 8 0 

RX Decimal, 16 bit: 0 2304 256 1025 264 

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 1

Hi @ALackOfNumbers

You can use a Script like this combine to two consecutive bytes in a word:

Protocol.UART.Receiver()
var rg = []
while(wait()){
    var t = Protocol.UART.ReceiveArray()
    if(!t.length) continue
    rg = rg.concat(t)
    while(rg.length>1){
        var v1 = rg.shift() 
        var v2 = rg.shift() 
        print(v1,v2)
        print((v1<<8)+v2) // MSB first
    }
}

image.thumb.png.c0b3f2f4c1968e5a7ff5b82b08e745a8.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...