PIC24 Support Libraries
The uC/PC data transfer protocol

The uC/PC data transfer protocol

The uC/PC data transfer protocol is a simple protocol to exchange data between a PC and a PIC over the UART. The example given below and implemented in this library applies to the PIC24/dsPIC33 series, though porting it to other microcontrollers is straightforward.

Usage sketch

#include "pic24_all.h"
#include "dataXfer.h"
// Indexes of all the variables to be transferred.
enum { U16_NUMCHARS_NDX, C_NDX };
// Number of characters to print on each line.
#define CHARS_PER_LINE 10
int main(void) {
char c;
uint16_t u16_numChars = 0;
// Initialize
configBasic(HELLO_MSG);
// All variables received by the PIC must be specified.
// Params: Index Variable PC can change Format Description
SPECIFY_VAR(U16_NUMCHARS_NDX, u16_numChars, TRUE, "%hu", "Number of characters received");
SPECIFY_VAR(C_NDX, c, FALSE, "%c", "Character entered");
while (1) {
// For debug support, send the index and char received.
sendVar(U16_NUMCHARS_NDX);
sendVar(C_NDX);
// Echo a character
c = inCharXfer();
outChar(c);
// Add a CR every CHARS_PER_LINE
if ((u16_numChars++ % CHARS_PER_LINE) == 0)
outChar('\n');
}
}

Examples

See the bottom of the example directory page.

Design goals

Error cases

Protocol