AddThis Social Bookmark Button

Have you ever been captured by Autobaud?

I started mucking around with a dsPic4011 few months ago, using MPLAB and C30. I was quite happy since I was able to run an "hello world" application in a very short time. Not only did the MPLAB and C30 installation go smoothly but coping and pasting code available on the C30 peripherals library, programming uart1 and timer1 was a piece of cake! The following code, used to program uart1 is available on microchip docs :

/* Configure UART1 module to transmit 8 bit data with one stopbit. Also Enable loopback mode */

baudvalue = 5;

U1MODEvalue = UART_EN & UART_IDLE_CON & UART_DIS_WAKE & UART_DIS_LOOPBACK &

UART_EN_ABAUD & UART_NO_PAR_8BIT & UART_1STOPBIT;

U1STAvalue = UART_INT_TX_BUF_EMPTY & UART_TX_PIN_NORMAL &

UART_TX_ENABLE & UART_INT_RX_3_4_FUL & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR;

OpenUART1(U1MODEvalue, U1STAvalue, baudvalue);

Well a coupla weeks ago, I started a new project with a 4011, with more peripherals involved. Since I'm a true believer of reusable code I imported the "hello world" code, recompiled just to make sure that things were properly set then I started the real project.

First of all I wrote some test code to set up and run input capture2, it worked fine, I then wrote test code for 2 PWM outputs, so far so good. I also needed uart2, so I simply copied code from uart1 to open it (changing where necessary 1 to 2) and it worked. At this point I had all the necessary pieces ready to build up the whole application. I did it and ....... the input capture2 refused to work! WHY ! I confess I lost a few hours to relate the problem to a specific block of code!

Well to make a long story short, I did not take notice that Microchip code enables autobaud rate when opening uart1(UART_EN_ABAUD). This prevents input capture1 operation. Guess what happens when autobaud is enabled on uart2 ? Yeah input capture 2 is disabled too.

Honestly it took me a while to find about this error also because autobaud is not even mentioned in the input capture section of the 4011 manual. And as usually Mr. Murphy made sure that I did not use input capture1 (when uart1 was already used). I solved this problem replacing UART_EN_ABAUD with UART_DIS_ABAUD
.

So to avoid to make a fool of your self use canned code, but make sure you know exactly what it does ...