Forum Discussion
17 Replies
- Altera_Forum
Honored Contributor
--- Quote Start --- I don't know how to start --- Quote End --- Go through a NIOS II tutorial and create a "Hello World!" example. Have that example send data to a regular UART, and connect your FTDI interface to those pins. At that point you have a communications channel between your FPGA NIOS II processor, and your PC. Modify the NIOS II code so that it receives commands or data over the serial port, and then processes that data, eg., write to memory or read from memory. Write some MATLAB code to create and send the serial commands to the NIOS II processor, and then parse the response. Once you have the ability to write and read FPGA memory from MATLAB, you can then modify your FPGA code to add custom logic, eg., an FFT, and then you can send data to memory, program a DMA controller to stream it to the FFT, and stream the result back to memory, and once the FFT completes, you can read the destination memory from MATLAB and compare the result to the FFT model. Cheers, Dave - Altera_Forum
Honored Contributor
--- Quote Start --- Go through a NIOS II tutorial and create a "Hello World!" example. Have that example send data to a regular UART, and connect your FTDI interface to those pins. At that point you have a communications channel between your FPGA NIOS II processor, and your PC. Modify the NIOS II code so that it receives commands or data over the serial port, and then processes that data, eg., write to memory or read from memory. Write some MATLAB code to create and send the serial commands to the NIOS II processor, and then parse the response. Once you have the ability to write and read FPGA memory from MATLAB, you can then modify your FPGA code to add custom logic, eg., an FFT, and then you can send data to memory, program a DMA controller to stream it to the FFT, and stream the result back to memory, and once the FFT completes, you can read the destination memory from MATLAB and compare the result to the FFT model. Cheers, Dave --- Quote End --- Hi Dave, Thank you. I managed to get the hello world example working. I have two questions in mind: I got data from fpga to my Nios processor where I can display the values on the Terminal window in Altera Monitor Program, I am thinking that I can save these data in sdram or a file and plot these data directly from Nios in pc, why do I still need the uart? forgive my poor understanding, i know this is definitely a newbie question, please forgive The second question is , i just want to plot graph to Matlab, does it mean I just need txdata but not rxdata? The third question is, i have created uart component in Qsys, I also have Matlab coding to plot graph, but I guess I need a bridge to interconnect these two, does it have to do with iord_altera_avalon_uart_rxdata(uart_base)? Could you please link me to an example that use this command (iord_altera_avalon_uart_rxdata(uart_base))? Thanks a lot! - Altera_Forum
Honored Contributor
--- Quote Start --- Go through a NIOS II tutorial and create a "Hello World!" example. Have that example send data to a regular UART, and connect your FTDI interface to those pins. At that point you have a communications channel between your FPGA NIOS II processor, and your PC. Modify the NIOS II code so that it receives commands or data over the serial port, and then processes that data, eg., write to memory or read from memory. Write some MATLAB code to create and send the serial commands to the NIOS II processor, and then parse the response. Once you have the ability to write and read FPGA memory from MATLAB, you can then modify your FPGA code to add custom logic, eg., an FFT, and then you can send data to memory, program a DMA controller to stream it to the FFT, and stream the result back to memory, and once the FFT completes, you can read the destination memory from MATLAB and compare the result to the FFT model. Cheers, Dave --- Quote End --- Forgive me for another question, this is the code from the manual, what I dont understand is how by running this example the code can read the data from uart since it defines the strings here (char *str = "Hello from NIOS II\n" ) but not reading directly from uart? I could not find how to read and write from/to uart. # include <stdint.h># include "system.h" int main(void) { volatile uint32_t *uart = (volatile uint32_t*) UART_BASE; char *str = "Hello from NIOS II\n"; while (1) { char *ptr = str; while (*ptr != '\0') { while ((uart[2] & (1<<6)) == 0); uart[1] = *ptr; ptr++; } } return 0; } - Altera_Forum
Honored Contributor
--- Quote Start --- I got data from fpga to my Nios processor where I can display the values on the Terminal window in Altera Monitor Program --- Quote End --- I have not used that tool. If it uses the JTAG-UART, then its probably not that easy to write custom software for it. Others might be able to comment. --- Quote Start --- I am thinking that I can save these data in sdram or a file and plot these data directly from Nios in pc, why do I still need the uart? --- Quote End --- Why think - just do it. Chances are that in the process of trying to do it, you find you cannot. That is why I recommended using a UART, since I know interfacing to that is trivial. You can access a UART directly from MATLAB. --- Quote Start --- i just want to plot graph to Matlab, does it mean I just need txdata but not rxdata? --- Quote End --- You'll need both. Ignore the fact that you are talking to an FPGA for a minute, and consider that you are trying to communicate between two processors; your MATLAB program is one process, and your NIOS II process is another. If you were to try to connect two PCs and have two instances of MATLAB communicate, how would you do that? First you would define a protocol, eg., lets say the protocol was to read and write data, with the read command being the string "r <address> <length>", and the write command being "w <address> <length> <data>", where address, length, and data are hexadecimal strings. Once you have that working, you can write a MATLAB script to communicate with the NIOS II processor, which in turn accesses the FPGA memory. --- Quote Start --- The third question is, i have created uart component in Qsys, I also have Matlab coding to plot graph, but I guess I need a bridge to interconnect these two, does it have to do with iord_altera_avalon_uart_rxdata(uart_base)? Could you please link me to an example that use this command (iord_altera_avalon_uart_rxdata(uart_base))? --- Quote End --- Sorry, I don't use NIOS II, but its "just a serial port", so work on it until you understand it. Those commands look very low-level. You should be working at a higher-level, i.e., with the C stdio library functions, but that assumes the NIOS II support library provides the hooks (stubs) to connect to the stdio functions. --- Quote Start --- I could not find how to read and write from/to uart --- Quote End --- You'll have to read the Altera documentation. The fact that the interface is a UART should be "hidden" from you. The interface should be the C/C++ stdio interface, or a file descriptor to the serial port. I can't really help with your NIOS II coding questions, you're better off asking a new question on the forum. Though these questions are fairly fundamental to using an embedded processor, and should be answered in Altera's documentation. So please take the time to read Altera's documentation, and run a "Hello World!" example - where you should see they use printf() not some UART command. Cheers, Dave - Altera_Forum
Honored Contributor
--- Quote Start --- Does it have a 100-mil header for GPIO? Buy an FTDI UM245R module from Digikey for $20 and it'll give you a USB-to-Serial interface to the board. The FPGA interfaces to the UM245R via an 8-bit parallel FIFO mode (8-bits data, and 4 control signals for the FIFO). MATLAB can then talk to the board like its a serial port. Cheers, Dave --- Quote End --- Hi Dave, I am able to read data from FPGA to Nios processor, then transmit this data to Uart component created in Qsys. Can I ask one silly question, I still do not understand why do I need FTDI UM245R module? Without FTDI UM245R module, I thought MATLAB can still talk to serial port, isn't it?? Please correct me if this is wrong. Thank you - Altera_Forum
Honored Contributor
--- Quote Start --- I am able to read data from FPGA to Nios processor, then transmit this data to Uart component created in Qsys. Can I ask one silly question, I still do not understand why do I need FTDI UM245R module? Without FTDI UM245R module, I thought MATLAB can still talk to serial port, isn't it?? --- Quote End --- If you look back at the start of this thread, the person that originally asked the question indicated that their kit did not have a UART interface. If the development kit you are using has a built-in RS232 interface or USB-to-UART interface, then you do not need an FTDI device. If someone does need a USB-to-UART interface, rather than the UM245R, its possible to use FTDI breakout cables like the C232HM. The breakout cable can be connected to the 100mil headers that are present on most development kits. Cheers, Dave - Altera_Forum
Honored Contributor
--- Quote Start --- If you look back at the start of this thread, the person that originally asked the question indicated that their kit did not have a UART interface. If the development kit you are using has a built-in RS232 interface or USB-to-UART interface, then you do not need an FTDI device. If someone does need a USB-to-UART interface, rather than the UM245R, its possible to use FTDI breakout cables like the C232HM. The breakout cable can be connected to the 100mil headers that are present on most development kits. Cheers, Dave --- Quote End --- Yes, you are right, thank you for the clarification.