Forum Discussion
Altera_Forum
Honored Contributor
11 years agoThis is difficult to read through....
I suggest make yourself a main.c and main.h files. In main.c include main.h In main.h include your drivers (system.h, sys/alt_irq.h, altera_avalon_uart_regs.h, whatever else you wany, AND InterruptHandlerforUart.h) In InterruptHandlerforUart.h also include system.h and altera_avalon_uart_regs.h for safety... In main.c: first put in the void InitUart(){ .... } routine you have then (as in the last thing you do) put in the int main() {....} routine in int main() you want to include: call out InitUart and your PutUart you basically do this already just make sure the int main() is you last routine So for transmitting data you have this: while(1) { unsigned char txdata [4]={2, 8, 5,6}; PutUart1(&txdata); <==================== this line right here isn't going to work since PutUart is expecting a character not an array } What I would do would be: unsigned char txdata[4]={0}; //initialize with zeros int i = 0; // array position while(1){ txdata[0]=2; txdata[1]=8; txdata[2]=5; txdata[3]=6; // you can also initialize with {2,8,5,6} //Then in a for loop spit out each character from the array for(i=0;i<4;i++){ PutUart(txdata[i]); } } So try that. Hopefully you didn't modify the InterruptHandlerforUart apart from InitUart1.... (I keep harping on this because at this point you just want to see if it'll work, you can modify once you verify functionality). Note: 1. You don't need to add this line "#define UART1_BASE 0x00002000" to the code because it is already defined in system.h! This is why we include it in the first place. It contains all the address and other parameters of peripheral that you placed in qsys. 2. I said this in the beginning, but separate you main program to another c file (main.c). It will make the code much cleaner.