Printf on multiple uart xc8

80 Views Asked by At

I used ccs a lot and now I'm starting on xc8.

when using more than one uart in ccs, name a stream configuration uart and use fprintf(stream,"TEXT");

Example:

#use rs232 (UART1,BAUD=115200, XMIT=PIN_C6, RCV=PIN_C7, PARITY=N, BITS=8,errors,TIMEOUT=1000,STREAM=main)

#use rs232 (UART2,BAUD=115200, XMIT=PIN_B0, RCV=PIN_B1, PARITY=N, BITS=8,errors,TIMEOUT=1000,STREAM=minor)

void main(){
    fprintf(main, "\r\nUART1");
    fprintf(minor, "\r\nUART2");
}

I wonder if anyone has an example of doing this in xc8

1

There are 1 best solutions below

0
ftraxx On

The best I think you can do is this:

uint8_t printEUSART = 0;

void putch(char txData)
{
    if (printEUSART == EUSART2) {
        EUSART2_Write(txData);
    }
    else {
        EUSART1_Write(txData);
    }
}

In main, to print the first USART:

printEUSART = EUSART1;
printf("%s\r\n", string);

In main (or other functions), to print the second USART:

printEUSART = EUSART2;
printf("%s\r\n", string);