I have a Spartan 6 that's collecting some data I need to send over serial to a python script where it can be displayed on my PC.
This is actually the first time I've ever dug into serial communications (I don't count programming arduinos)
So I'm essentially specifying the data format myself from the FPGA which makes me think I should easily be able to sync this communication, but it seems a little more difficult than I thought.
This is my current approach:
The data I am sending is 16 bits long, and I assumed that I needed to send the start/stop bits manually, so my serial VHDL module just reads in the 16 bit value and concatenates like this:
output_vector <= '1' & din & '1'
From there, a counter just loops from
0 to 17, assigning the
Tx line to the current index of the
So I am not sure if my assumption is correct here. Do the start and stop bits need to be manually transmitted like this? And how does the receiving end know a start/stop 1 from any other 1 in the data signal?
The counter I mentioned previously cycles through at a rate of
195.3125 kHz, so I added 16 bits for data + 2 start/stop bits = 18 bits total.
195312.5 / 18 = 10,850.694444444
So in my python script, I set the baud rate to
10,851 as that is the nearest integer value. Even so, I don't understand how the receiving end synchronizes up with the transmitting side so it is actually in line and gets correct data.
My python script is pretty simple:
import serial def convert_to_ascii(text): return " ".join(str(ord(char)) for char in text) ser = serial.Serial(12) ser.baudrate = 10851 print ser.name while(True): data = ser.read(2) print(convert_to_ascii(data))
I ultimately need some way of combining the 2 bytes being read into 1 single integer value, but I haven't quite figured that out yet either. The script is receiving data, but I cannot verify it is correct at all.
There is also mention of some sort of
Xon/Xoff transmission relating to
software flow control in the user guide for my FPGA board (Digilent Nexys 3), but I really have no idea how to use that. I'm totally lost here on how to synchronize up this simple serial connection.