void main(void) { unsigned short l_us_temp; //Disable watchdog timer WDTCN = 0xDE; WDTCN = 0xAD; ExtCrystalOsc_Init(); //Initialise crossbar and GPIO Port_Init(); EMIF_Init(); //Initialise Timer 0 Timer0_Init(); //Initialise Timer 2 Timer2_Init(); //Initialise Timer 4 Timer4_Init(); //Initialise UART0 UART0_Init(); //Initialise UART1 UART1_Init(); //Initialise ADC ADC0_Init(); //Initialise DAC DAC0_Init(); DAC1_Init(); //Initialise PCA0 PCA0_Init(); //Initialise INT0_N & INT1_N Ext_Interrupt_Init(); //lsl : 04 Jan 2011 : 0852hrs : disable Watchdog timer temporarily //Initialise Watchdog Timer // Watchdog_Init(); //Initialise SPI0 SPI0_Init(); //------------------------ //Reset IMU-A, IMU-B & GPS SFRPAGE = CONFIG_PAGE; IMU_A_CS = 1; IMU_B_CS = 1; IMU_A_RST = 0; IMU_B_RST = 0; GPS_RST = 0; delay_ms(1); IMU_A_RST = 1; IMU_B_RST = 1; GPS_RST = 1; delay_ms(1); //--------------------------------------------------------- //lsl : 31 Dec 2010 : 1046hrs: Initialise variables : begin g_us_rx0_ptr = 0; g_us_tx0_ptr = 0; g_us_rd0_ptr = 0; for (l_us_temp = 0 ; l_us_temp < RX_BUFFER_SIZE ; l_us_temp++) { g_c_rx0_buffer[l_us_temp] = 0; } g_us_rx1_ptr = 0; g_us_tx1_ptr = 0; g_us_rd1_ptr = 0; for (l_us_temp = 0 ; l_us_temp < RX_BUFFER_SIZE ; l_us_temp++) { g_c_rx1_buffer[l_us_temp] = 0; } //lsl : 05 Jan 2011 : 1916hrs : tested UART1_Buffer = "\rlog version\r\n"; g_us_tx1_cmd_length = 14; //lsl : 06 Jan 2011 : 1916hrs : tested ok //UART1_Buffer = "frequencyout enable 2 4\r\n"; //g_us_tx1_cmd_length = 25; g_uc_gps_init = 0; //Enable global interrupts EA = 1; //----------------------------------------------------------------------------- // Start of WHILE LOOP //----------------------------------------------------------------------------- while (1) { //Toggle LED_1 & LED_2 SFRPAGE = CONFIG_PAGE; LED_1 ^= 1; LED_2 ^= 1; } //----------------------------------------------------------------------------- // End Of WHILE LOOP //----------------------------------------------------------------------------- }
I could not able to transmit the data through the UART when i run the program. But when i put a breakpoint, it seems working fine. May i know where is the problem? i seems like i could not find it. thanks
In your original post, you just show writing to the buffer:
//lsl : 05 Jan 2011 : 1916hrs : tested UART1_Buffer = "\rlog version\r\n"; g_us_tx1_cmd_length = 14;
But you haven't shown anything that will actually start the transmission!
Also, just as an aside, the 'else' clause is pointless here:
if (g_us_tx1_cmd_length != 0) // If buffer not empty { SBUF1 = UART1_Buffer[g_us_tx1_ptr]; // Transmit to Hyperterminal g_us_tx1_ptr++; // Update counter g_us_tx1_cmd_length--; // Decrease array size } else { g_us_tx1_cmd_length = 0; // Set the array size to 0 }
Isn't it ?!
Won't cause any problems - it's just pointless.
First i store the command in the UART1 Buffer after that when it receive the command it will set it to T1 =1; so that it will go into the loop above you mention.
char putchar(char l_c_txdata) { //Save current SFR Page char SFRPAGE_SAVE = SFRPAGE; if (l_c_txdata == '\n') { //Carriage Return l_c_txdata = 0x0D; } else if (l_c_txdata == '\r') { //Line Feed l_c_txdata = 0x0A; } if (g_uc_uart == 0) { //Use UART0 SFRPAGE = UART0_PAGE; //Wait for transmit complete while (!TI0); //Clear TI0 flag TI0 = 0; //Send character SBUF0 = l_c_txdata; } else if (g_uc_uart == 1) { //Use UART1 SFRPAGE = UART1_PAGE; //Wait for transmit complete while (!TI1); //Clear TI1 flag TI1 = 0; //Send character SBUF1 = l_c_txdata; g_us_tx1_ptr++; } //Restore the SFRPAGE SFRPAGE = SFRPAGE_SAVE; return l_c_txdata; } //----------------------------------------------------------------------------- // _getkey //----------------------------------------------------------------------------- // // // This routine overloads the standard _getkey() library function to support // either UART0 or UART1, depending on the state of the global variable <g_uc_uart>. // //----------------------------------------------------------------------------- char _getkey() { char c; char SFRPAGE_SAVE = SFRPAGE; if (g_uc_uart == 0) { SFRPAGE = UART0_PAGE; while (!RI0); // Wait for byte to be received c = SBUF0; // Read the byte RI0 = 0; } else if (g_uc_uart == 1) { SFRPAGE = UART1_PAGE; while (!RI1); // Wait for byte to be received c = SBUF1; // Read the byte RI1 = 0; } //Restore the SFRPAGE SFRPAGE = SFRPAGE_SAVE; return (c); }
Hmmm.. if i have any wrong mistake in writing in transmission of the command, could you guide me where should i change?
thanks
"First i store the command in the UART1 Buffer"
Yes, you've shown that.
"after that when it receive the command"
What what "receives" the command?
After sending the command of the through the transmit untill my end of the command. i would wait for the GPS receiver to send me data through UART 1 where the receive flag anknowledge a "1". therefore i will read from the uC memory from the the UART rx buffer.
But you said, in your original post, that your problem is that nothing is sent!
today i did proble the transmit port from the uC and i could able to see the command send through oscillscope. At first, my guess was the transmit part got problem but i seems like not. I m totally lost about this because i not really sure where my problems lies at.
If you're lost when you have all the code and the hardware and all the information in front of you, how do you expect anyone else to know what's going on when we can't even see all of your code?!
Where did the code come from? Presumably, you didn't write it yourself? Can you contact the original author?
You seem to have basic problems with the operation of your buffered UART "driver". You really need to isolate that part and concentrate on understanding it and getting it working. The GPS unit and everything else are just unnessary distractions & complications at this point.