• AVR Freaks

Hot!Harmony v2 DRV_USART0_WriteByte stuck at 9 charc

New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2020/03/11 02:46:50
  • Location: 0
  • Status: offline
2020/03/17 20:51:34 (permalink)

Harmony v2 DRV_USART0_WriteByte stuck at 9 charc

I'm a total beginner at embedded programming and i followed an online guide regarding writing characters through rs232.
I'm using pic32mx470f512L with Harmony 2 and their Static USART driver with interrupt mode, byte model support and callback operations.
However whenever i pass in a long string from the terminal, the chip only writes back 9 characters from the string.
ex) sending "abcdefghijkl+" I only get back from the chip "abcdefghi"
2) Also I tried adding an if (!DRV_USART_TRANSFER_STATUS_TRANSMIT_FULL) statement in the while loop, but this causes the program to never pass/enter the code inside the if block.
static char buf[40];
volatile char tmp;

void ReceiveEvent(const SYS_MODULE_INDEX index) {
    tmp = DRV_USART0_ReadByte();
    buf[i] = tmp;
    if (tmp == '+') {
        i = 0;
        memset(buf, 0, sizeof buf);

void display(char *buffer) {
    while (*buffer != NULL) {
void APP_Initialize(void) {
/* Place the App state machine in its initial state. */
appData.state = APP_STATE_INIT;

void APP_Tasks(void) {
    /* Check the application's current state. */
    switch (appData.state) {
            /* Application's initial state. */
        case APP_STATE_INIT:
            bool appInitialized = true;
            /* Enable the Receive interrupt source */

            if (appInitialized) {
                appData.state = APP_STATE_SERVICE_TASKS;

Paul PortSol
Super Member
  • Total Posts : 636
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: Harmony v2 DRV_USART0_WriteByte stuck at 9 charc 2020/03/18 09:05:33 (permalink)
4 (1)
1. The PIC32 have FIFOs on UART Tx/Rx. Your writes will fill up the Hardware FIFO and then fail discarding further data immediately. Amount of data that gets out depnds on UART data rate, FIFO size, PIC system clock, and any flow control.
2. Some PIC's have UART hardware issues, see the PIC's errata on microchip webpage near PIC32 datasheet. Read about things that can happen with UART for your PIC (Possible glitch upon overflow).
3. Simple: printf or other output routine writes data to a buffer (i.e. Ring Buffer, see wikipedia). Then periodically your main loop (app.c) checks if space in FIFO and copies data from ring buffer to FIFO (using write to UART function). The UART is so slow compared to PIC this works fine in most cases, without any Tx Interrupt, and without ever overflowing the Tx FIFO (Rx Interrupt is useful to prevent Rx overflow).
4. If you are using Tx Interrupt then you may miss an interrupt upon Tx overflow and then not get further interrupts - you need to handle such cases in your code, or do like (3) above. 
5. Harmony has a few ways of handling FIFO, above is for raw byte transfer. Feel free to try the other harmony methods.
Jump to:
© 2020 APG vNext Commercial Version 4.5