Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC18F1320 USART using MCC18 USART library

Status
Not open for further replies.

eanema

Member level 2
Joined
Sep 30, 2009
Messages
43
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,740
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):


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:

Turns out this was actually a problem with the MAX232 circuit after all. I must have damaged it soldering it down...

thanks for the consideration
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top