LPC1227 UART to Bluetooth Module Help

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1227 UART to Bluetooth Module Help

265 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nelmak on Mon Aug 27 19:59:32 MST 2012
Hi,

I am trying to send a few numbers to my Android phone using a Bluetooth module with my LPCXpresso board containing a LPC1227 using the UART module.

I have code below
  
int main()
{

uartinit(9600);

      while(1)
      {
              for(j = 0; j < 10; j++)
                {
                    check = transmit(4);
                    //check = transmit(d);

                    if(!(check == 0))
                    {
                        printf("Transmit error");
                    }

                }
       }
}


void uartinit(uint32_t brate)
{
    uint32_t regVal, Fdiv;

    NVIC_DisableIRQ(UART0_IRQn);

    //Enable Pins 0_1 and 0_2 for UART0
    LPC_IOCON->PIO0_1 &= ~0x07;    /* UART0 I/O config */
    LPC_IOCON->PIO0_1 |= 0x02;     /* UART0 RXD LOC0 */
    LPC_IOCON->PIO0_2 &= ~0x07;
    LPC_IOCON->PIO0_2 |= 0x02;     /* UART0 TXD LOC0 */

    /* Enable UART 0 clock */
    LPC_SYSCON->PRESETCTRL |= (0x1<<2);
    LPC_SYSCON->SYSAHBCLKCTRL |= (0x1<<12);
    LPC_SYSCON->UART0CLKDIV = 0x1;     /* divided by 1 */

    LPC_UART0->LCR = 0x83;             /* 8 bits, no Parity, 1 Stop bit */
    regVal = LPC_SYSCON->UART0CLKDIV;
    Fdiv = ((SystemCoreClock/regVal)/16)/brate ;    /*baud rate */

    LPC_UART0->DLM = Fdiv / 256;
    LPC_UART0->DLL = Fdiv % 256;
    LPC_UART0->LCR = 0x03;        /* DLAB = 0 */
    LPC_UART0->FDR = 0x10;        /* set to default value: 0x10 */
    LPC_UART0->FCR = 0x07;        /* Enable and reset TX and RX FIFO. */

    /* Read to clear the line status. */
    regVal = LPC_UART0->LSR;

    /* Ensure a clean start, no data in either TX or RX FIFO. */
    while ( (LPC_UART0->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) );

    NVIC_EnableIRQ(UART0_IRQn); //Re-enable interrupt after changes

    //LPC_UART0->IER = IER_RBR | IER_THRE | IER_RLS;    /* Enable UART interrupt */
}

int transmit(char val)
{
    //printf("Trying transmit\n");
    while(!(LPC_UART0->LSR & (0x01<<5)));
    LPC_UART0->THR = val;
    //printf("Transmitted\n");
    return 0;
}


I copied and pasted parts of the code that only matter so please ignore any inconsistencies. Is this how I would set up my UART? I tested the module with the small_printf example code and it printed everything just fine so I know it works. Therefore, it has to be a problem with my setup. I just want to send integer values over the module. How would I set this up?

Thanks
0 Kudos
1 Reply

229 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Wed Aug 29 14:38:01 MST 2012
Hello nelmak,

What kind Bluetooth module are you using and how is it connected to the LPCXpresso kit?
0 Kudos