Forum Discussion
Altera_Forum
Honored Contributor
11 years ago --- Quote Start --- This 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. --- Quote End --- Thank you very much Krasner, with your help, I am able to use the codes provided and modified main.c to transmit data to serial port. However, I am still facing the same problem as before, previously, as mentioned earlier, I do not implement uart interrupts, I was using polling previously, although I was able to plot the graph but data was not updated as often as it should be (as I posted in this thread http://www.alteraforum.com/forum/showthread.php?t=48165). Now, I have implemented interrupt, the same issue persists, I have no idea what perspective I should look into to troubleshoot this problem, I can send you the code, I am having the issue where the data is not updated as frequent as desired. In my C code, I want the parameter say parameter A to be updated every 0.2 seconds, so I expect to see 30 sets of data being updated within 6 seconds, however, it is only updated 3 sets within 6 seconds, I can see that the sequence/order it updates is correct, just that it is updated slower that it is supposed to be. I suspect two reasons and so I tried: 1.Interval timer core, so I change the timer from 0.2 seconds to 0.1 seconds, it makes no difference to the results though 2. Matlab code, timeout parameter, I set it to be 7 seconds, if I set it less than this, I will get an error saying the serial: data not returned within the timeout period. What I currently have are as follows:int main(void) { // open main printf("\n\nHello NiosII!!!!!\n"); InitUart(); // do other processing, read adc, interval timer etc //then call for PutUart1 int z = 0; for(z=0;z<12;z++) { unsigned char bb; bb= (char) txdata1[z] + 48; PutUart1(bb); } void InitUart() { int context_uart1; InitUart1();   alt_ic_isr_register(UART1_IRQ_INTERRUPT_CONTROLLER_ID, UART1_IRQ,IsrUart1,&context_uart1,0x0);   alt_ic_irq_enable(UART1_IRQ_INTERRUPT_CONTROLLER_ID, UART1_IRQ); } I have no idea what perspective I should look into to troubleshoot this problem, just need some idea from you, appreciate your help....My first question, how do I know/check if interrupts has been enabled? my second question is, I don't see the difference between the polling and interrupt implemented in my system, the only difference is, in the Matlab code timeout parameter, previously it worked with 5 seconds, now I can only set it to 7 seconds otherwise I will get an error saying the serial: data not returned within the timeout period. My third question, I didn't make any changes to the InterruptHandlerforUart.c (except printf), I want to know, what changes should I make to the InitUart1() function below since I am not doing anything with rrdy_mask and rx buffer, I only transmit but not receive. void InitUart1() { IOWR_ALTERA_AVALON_UART_CONTROL(UART1_BASE, ALTERA_AVALON_UART_CONTROL_RRDY_MSK); }   My fourth question, could it be the problem with the sequence/order? the sequence the program will call is InitUart, then adc read/sorting/timer etc, PutUart, is there anything wrong with this order?