XC8 software USART library?

Thread Starter

spinnaker

Joined Oct 29, 2009
7,815
I would like to make a full binary out port available to be able to quickly output a full byte of data.

My problem is that the only full port I have also has a hardware serial I/O. I need serial I/O to communicate to TTY software on the PC.

One thought I had was to use the software library. I could have sworn there was an implementation for it on one of Microchip's compilers. But I am using XC8. I check the docs and all I am seeing is the hardware implementation. Is the software version still supported?

FYI: I will be using external interrupts and timer interrupts. Will I have an issue with software USART with interrupts.

I do have one other serial port available but it is being used for SPI. I could share it but I imagine it would get real messy building chip select circuit (the devices I am using do not have their own) and have to reconfigure the port every time I want to use it for the different devices.
 

joeyd999

Joined Jun 6, 2011
4,239
FYI: I will be using external interrupts and timer interrupts. Will I have an issue with software USART with interrupts.
Yes. You will need to disable interrupts during transmission/reception. UART is finicky about timing.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,815
If I use the hardware library I should not have a problem with interrupts correct?

Where is the software library documentation?

How would I know when to disable interrupts when the user is pressing a key on the keyboard? Currently I poll the serial in buffer. Should I be using interrupts there too?
 

joeyd999

Joined Jun 6, 2011
4,239
If I use the hardware library I should not have a problem with interrupts correct?

Where is the software library documentation?

How would I know when to disable interrupts when the user is pressing a key on the keyboard? Currently I poll the serial in buffer. Should I be using interrupts there too?
Since I write .asm, I have no idea where you should look for library docs.

With a hardware interrupt driven (E)U(S)ART, there is no issue with other interrupts.

You must manually capture the start pulse with a software UART, though, and it needs to be done on a timely basis. Not that I've ever implemented one, but it seems that you'd pretty much have to constantly poll the receiver pin in main(), not leaving much time for anything else.

On the other hand, you could make one of your external ints the RX pin, and trigger an interrupt on the falling edge of the start pulse. Then, processes the byte manually in the ISR. This will satisfy the timing requirement (and help with bit time alignment) at the expense of locking up your program for the duration of the byte(s).

Edit: Oh, and while I can write C, I'd have no idea how to get the timing correct using C constructs. I'd probably wind up inlining .asm code.
 

GopherT

Joined Nov 23, 2012
7,983
I'd probably wind up inlining .asm code.
And that doesn't seem to be very convenient in the XC8 compiler. Easier formatting on the higher bit compilers for some reason. Stick with .asm.

What compiler do you use to convert .asm to hex?.
 
Top