Does anyone know how easy/hard it is to use USART to send back data to my computer about a PIC microcontroller's variable states, for example to the terminal?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
On which PIC especially?
Which baud rate?
Continuous data streaming or sporadic byte sending?
Receiving at the same time (full duplex)?
What oscillator mode (internal RC or external clock/crystal)?
At which core clock frequency?
How many data per second?
How many data at all?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Where the 51 is the divider for the baudrate (in this case its 115200 with a pic running at 48MHz). The stdout/stdin thing is needed to tell sdcc libs where to send the data to.
Finaly you need to somehow overwrite the putchar function to adapt it to your chip. For a pic this is:
void putchar(char c)
{
// Wait for TXREG to be ready
while(!PIR1bits.TXIF);
// Place char in TXREG - this starts transmition
TXREG = c;
}
Now you can use normal printf and watch the output with minicom etc. BE carefull to have at least 0x64 stack when using printf and of course to use a crossed cable.
If you want to read from the usart use
if (usart_drdy()) {
usart_gets(my_string, my_length);
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Didn't expect to get a reply that quickly, so many thanks for the helpful replies. I'm trying to verify the readings of the a/d converter. I'm running on a PIC18F2620 on an internal oscillator at 8 MHz I believe. The sampling frequency is calculated somehow by one of the sdcc enthusiasts to be 10 kHz. I haven't connected a circuit yet that would allow me to send data for USART yet, but I think presumably it's RS-232 and minicom display.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Does anyone know how easy/hard it is to use USART to send back data to my computer about a PIC microcontroller's variable states, for example to the terminal?
On which PIC especially?
Which baud rate?
Continuous data streaming or sporadic byte sending?
Receiving at the same time (full duplex)?
What oscillator mode (internal RC or external clock/crystal)?
At which core clock frequency?
How many data per second?
How many data at all?
Hi
Its damn simple:
just do
#include <usart.h>
later in your code open the usart with:
usart_open( USART_TX_INT_OFF & USART_RX_INT_OFF & USART_BRGH_HIGH & USART_CONT_RX & USART_EIGHT_BIT & USART_ASYNCH_MODE, 51);
stdout = STREAM_USART;
stdin = STREAM_USART;
Where the 51 is the divider for the baudrate (in this case its 115200 with a pic running at 48MHz). The stdout/stdin thing is needed to tell sdcc libs where to send the data to.
Finaly you need to somehow overwrite the putchar function to adapt it to your chip. For a pic this is:
void putchar(char c)
{
// Wait for TXREG to be ready
while(!PIR1bits.TXIF);
// Place char in TXREG - this starts transmition
TXREG = c;
}
Now you can use normal printf and watch the output with minicom etc. BE carefull to have at least 0x64 stack when using printf and of course to use a crossed cable.
If you want to read from the usart use
if (usart_drdy()) {
usart_gets(my_string, my_length);
}
Didn't expect to get a reply that quickly, so many thanks for the helpful replies. I'm trying to verify the readings of the a/d converter. I'm running on a PIC18F2620 on an internal oscillator at 8 MHz I believe. The sampling frequency is calculated somehow by one of the sdcc enthusiasts to be 10 kHz. I haven't connected a circuit yet that would allow me to send data for USART yet, but I think presumably it's RS-232 and minicom display.