The uC/PC data transfer protocol

The PC/uC data transfer protocol

The uC 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 u16_numChars = 0;

  // Initialize
  configBasic(HELLO_MSG);
  initDataXfer();

  // 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

The following programs use the data transfer protocol, providing working examples of its usage.

Design goals

Error cases

Protocol


Generated on Mon Oct 18 07:40:49 2010 for Python-on-a-chip by  doxygen 1.5.9