eanema
Member level 2
I have built a board to communicate with a PC using a MAX232 chip. Using the code provided below I can easilly and correctly receive bytes from the PC. The problem is that I cannot send a byte from the PIC to the PC. I have tested the hardware (by controlling the IO pin directly) so I know that the MAX232 chip is functioning properly. This means that the problem is a configuration problem with the PIC.
The program that I am currently testing with should send 0x40 to the PC every 500ms but nothing is received. Any comments about my code would be greatly appreciated.
thanks!
My main() function looks like this (msCounterX10 is incremented every 10 ms by a timer interrupt):
The program that I am currently testing with should send 0x40 to the PC every 500ms but nothing is received. Any comments about my code would be greatly appreciated.
thanks!
My main() function looks like this (msCounterX10 is incremented every 10 ms by a timer interrupt):
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 void main (void) { //call the initialization routines initHW(); // main program loop while (true) { // process receive buffer //processBuffer(); if (msCounterX10>50) { msCounterX10=0; WriteUSART(0x40); toggleLED(); } } }//main // My initHW() looks like this: void initHW (void) { // configure the digital IO pins and int osc TRISA=0x00; // set Port A: all pins as outputs PORTA=0x00; // set Port A: outputs to zero TRISB=0x00; // set Port B: all pins as outputs PORTB=0x00; // set Port B: outputs to zero OSCCON=0x70; // configure the internal oscillator (8MHz) // enable reading from data EEPROM EECON1=0x00; // configure timer 1 T1CON=0x85; // enable tmr1 as a 16bit counter and use // system clock as a source PIR1bits.TMR1IF=0; // clear the interrupt flag IPR1bits.TMR1IP=0; // set the propriety to low PIE1bits.TMR1IE=1; // enable the tmr1 interrupt // enable the EUSART RCSTAbits.SPEN=1; // Enable RX on the serial port ADCON1bits.PCFG5=1; // configure pin RB1 as digital IO ADCON1bits.PCFG6=1; // configure pin RB4 as digital IO TRISBbits.TRISB1=1; // configure pin RB1 as input TRISBbits.TRISB4=1; // configure pin RB1 as input IPR1bits.RCIP=1; // Make receive interrupt hi priority // configure the EUSART as 9600 baud, 8N1 in interrupt mode OpenUSART (USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 51); // configure the baud rate generator baudUSART (BAUD_8_BIT_RATE & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF); // enable interrupts INTCONbits.GIEH=1; // global enable high priority interrupts INTCONbits.GIEL=1; // global enable low priority interrupts RCONbits.IPEN=1; // enable interrupt priorities }
Last edited by a moderator: