1

I am using the above mentioned pic controller on explorer 16 board. I am trying to configure UART but it is not working My code looks something like this.

enter code here
#define Bit8_No_Parity          0x00
#define Bit8_E_Parity           0x01
#define Bit8_O_Parity           0x10

#define Stop_Bits_1             0
#define Stop_Bits_2             1


U2MODEBITS U2mode;
U2STABITS  U2Sta;

void Uart2_Init()
{
    U2BRG = 207;            // 9600 for 8 mhz
    U2MODE = 0x8000;
    U2STA  = 0x8400;
    U2mode.PDSEL = Bit8_No_Parity ;

    U2mode.STSEL = Stop_Bits_1;
    U2mode.BRGH = 1;


    U2Sta.UTXISEL1 = 1;
    U2Sta.UTXISEL0 = 0;
    U2mode.UARTEN  = 1;

    U2Sta.UTXEN    = 1;




 }


void Transmit_Byte(UCHAR_8 byte)
{
   while(U2Sta.UTXBF != 0 );
   U2TXREG = byte;

}

The above code is not working. I only initialize config bits and the Uart init function in my main file. Looking for some help.

Regards Sanket

Sanky
  • 13
  • 1
  • 6

1 Answers1

0

You seem to define variables (U2mode, U2sta) with the layout of registers (U2MODEBITS, U2STABITS) instead of using predefined register definitions in whatever your header is.

This means nothing is written to registers, and so nothing happens. Remove the declarations and write to the real bit versions of the registers that are all uppercase (C is case sensitive!) U2STATBITS, U2MODEBITS. These overlay the uint sized U2STA and U2MODE in memory, so you can mix writing to them.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89