LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Spartan 3E serial communication

Solved!
Go to solution
Hi I'm working with Spartan 3E and LabVIEW with the FPGA module,  I'm doing the serial communication with an RFID device, I can write and send all, but I can not read, reads either only the first two characters after that the read are wrong or invalid data, if somebody can help me, be grateful.

add what I've done so far and worked for the reading
Download All
0 Kudos
Message 1 of 15
(7,653 Views)

hello,

 

I was also having problems with the serial receive on the spartan 3E board.

I am not a professional in labview but i managed to update your program in my project.

The main problem in your program is that the timing in completely wrong...  This website shows the right diagram of how serial communication is used... http://en.wikipedia.org/wiki/Asynchronous_start-stop

 

So i presume you want to use a baudrate of 11520? then the 9µS is correct but you need to take the start bit in mind.. and in your program you check on the end of the bit you send so you need to edit the timing in that way so you check the status of the bits in the midle of the received bits.(this might be a bit confusing but check the timing diagram in attachment that will explain everything i hope)

in attachements you can find the exact timing and there will also be a picture of my program i made with the timings for a baudrate of 9600.

a brief explanation of the program:

The program waits for a faling edge on the receive input then it waits 156 µS then it will detect the first bit then it waits for 104µS to detect the second bit and so on. The for loop is used to set how many data bits you will receive (in my case the communication consist of 1 startbit, 8 databits and 1 stopbit). when the 8 databits are received then the program  converts the received data to an array indicator and a number.  As you  have probably noticed i do not wait for the stopbit. i ignore the stopbit because this is usualy just a waiting time to process data. and because i watch for a falling edge it will always mean that the next byte is being send so it will always receive if you want to receive more then 1 byte at a time i think it should work by putting everything within the whileloop in a for loop or make the while loop run untill for example 10 bytes are received.

 

kind regards

Snakebomber

 

P.S. sorry for any typing errors but i am not a native english speaker and let me know if it works for you.

Download All
0 Kudos
Message 2 of 15
(7,524 Views)
Hi thanks for your help, all ready i tried use your vi, and adjusting my own vi, but now the problem is the next, the vi just like yours not just read one character if not the entire buffer, but only show the last character, any suggestion? i wanna read determinate number of character's.
Thanks again:smileywink:
0 Kudos
Message 3 of 15
(7,468 Views)

Yes i found out that that was a bit tricky because i use the serial receive to receive 3 bytes the first is a specific number 254 the second is data byte 1 and the third is  databyte 2. The first byte is to have some kind of synchronisation (in my case the second and third  byte never have a value of 254)...

To create some kind of buffer for the serial receive i made use of the FIFO registers in labview FPGA.

 

A small explanation of how the piece of code works.

As you can see there are 2 whileloops now the lower whileloop is the same as i explained earlier (or simular because it could be that i made some small space saving changes...) but at the end you see that i use the FIFO write function

 

To create a FIFO: go to the project explorer right-click on the FPGA target select new => FIFO

A propperty dialog will appear where you can set the settings. I suggest you you click the help button for more info(if you use less then 20 received bytes at one time set it to flipflop it will save some memory on the FPGA).

When you select ok then you will see that there is a FIFO created in the fpga subtree. To place it on the block diagram just drag it from the project explorer to the block diagram.

If you right click the item on the block diagram you can select 3 methods "read", "write", and "clear" in the receive we want to write the data to the fifo.

( as you can see i used a "convert from boolean array to number" because the fifo doesn't work with boolean arrays.)

 i set the timeout value to -1 this means that it wil wait forever before it times out.

 

now for the upper while loop the functionality is as followed: again you see that the timeout is set to -1 so the whileloop will not loop any further because the FIFO read will never timeout so it waits untill there is something in the FIFO.

If there is something in the FIFO and for example it is not equal to 254 then the case is false (where in my case nothing happens) so the case will end and the whileloop is run again untill the FIFO read is equal to my startbyte 254 if that is the case then the second while loop will be active and i extract the 2 data bytes  by using a case structure that is connected with the loop iteration.

So the first time it is run the iteration will be "0" so i extract the first databyte by using the HDL node ( i use it because labview doesn't know how to convert from numer to bitlevel or from boolean array to bitlevel besides using a for loop and the index array function and  in VHDL this programmed very easily). You can also use a flat sequence to do the same (but i use my program to show the different ways to programming)

The false constant is to make sure the loop keeps running.

when te loop is run for the second time i extract the second byte and when the while loop runs for the third time i make the false constant to true so te whileloop will exit and run again in the upper whileloop waiting for the next set of bytes to be received

 

in attachement you will find the solution of the serial receive with the fifo registers.. this works fine for my program.

 

If you still have any question i wil do my best to answer them as quickly as possible

 

kind regards

Snakebomber

 

 

Message 4 of 15
(7,457 Views)
Solution
Accepted by topic author Emmanuelol

Hi i think i solved the problem, just add a sequence more, wich wait the stop to continue.

thanks for you help 😄

0 Kudos
Message 5 of 15
(7,319 Views)
Hi, pleas can you upload your VI?
0 Kudos
Message 6 of 15
(7,173 Views)
Hello
the attached file is a program shows the communication between PC and FPGA Spartan 3E.
 
It implement a Function where the FPGA is sending characters to the Host PC if the user is pushing a Button (“BTN_SOUTH”). I send over a “Hello World!” message. 
 
Now I want to change the program for dynamic communication ie I sent a character from PC to FPGA and I receive this character FPGA to the PC. Is it possible to do this program?
thank you for your support.
very urgent.
0 Kudos
Message 7 of 15
(5,547 Views)

hi,

 

yes it should be possible to edit the program in such a way that you can send data to the pc. The Spartan 3E converts the signals send out via the serial port to the correct format so your pc will understand this.

Serial communication is a communication that needs exact timing so as i said before check the diagram for the timing you need. (for your baudrate)

i found this PDF file that will explain step by step how to setup the serial communication so you can send data TO the pc.

 

http://www.google.be/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCMQFjAA&url=http%3A%2F%2...

 

First hit when i searched with google.

 

ooh btw the first topics ARE about receiving the serial signal (from a pc or other device) and processing it in the FPGA.

so try to read those files that are attached and try to understand them step by step (serial communication is a logical way of sending so its only logic thinking you need to understand the code)

 

kind regards,

 

0 Kudos
Message 8 of 15
(5,538 Views)

Hi

thank you for your attention to my topic
yes I read the document and I run the program, it works very well and I received on message on hyperterminale.
the programe that I want to do is to send a character from my PC (hyperterminale) to FPGA and I receive this character on my PC.
Is that I can send a character on the DB9 male (DTE) Spartan 3E card and I receive on the other DB9 (DCE)?
if yes please help me make the code.

0 Kudos
Message 9 of 15
(5,526 Views)

Hi Yassagem,

 

You can send on the DTE and receive on the DCE. Here is a link that shows how the connection should be made. It looks like the wiring should be straightforward. here are a few more links and examples on implementing RS232 communication with the FPGA.

 

http://zone.ni.com/devzone/cda/epd/p/id/2164

http://sine.ni.com/nips/cds/view/p/lang/en/nid/209123

 

Best,

tannerite

Tannerite
National Instruments
0 Kudos
Message 10 of 15
(5,513 Views)