2

I have a hardware with RN-41 bluetooth module and the lpc 214 arm microprocessor.Currently my device only sends data to the PC and I am trying to configure it to be able to receive some commands over bluetooth and perform certain actions e.g. blink LED,Shutdown etc.

I have a serial GUI in matlab which has buttons on it (LED ON,LED OFF,SHUTDOWN etc)where each button on being pressed sends a value associated with it to the hardware over a virtual serial port to perform a certain action.

Till now I have not been able to get my device to perform any action correctly.I definitely see the hardware responding to a button press in strange ways but never performs the desired action.I feel I may have configured the UART incorrectly. I am pasting some code associated with this issue here.

Any help would be greatly appreciated.

Thanks!

void setup_uart0(int newbaud, char want_ints)

{
baud = newbaud;
U0LCR = 0x83;   // 8 bits, no parity, 1 stop bit, DLAB = 1
U0DLM = 0x00;   // set for baud high byte
U0DLL = 0x06;   // set for baud low byte
U0FDR = 0xC1;   
U0LCR = 0x03; 
VICVectCntl1 = 0x00000026;
VICVectAddr1 = (unsigned int) UART0ISR;
VICIntEnable = (1<<6);
//PINSEL0 = 0x0F001555;
}


void UART0ISR(void)
{
    unsigned int i;
unsigned char ch;
U0IER = 0x01; 

while(!(U0LSR&0x01));
uart0_rx_buffer[uart0_rx_extract_idx++]=U0RBR;
uart0_rx_extract_idx %=UART0_RX_BUFFER_SIZE;
ch = uart0_rx_buffer;

for (i=0;i<8;i++)
uart0_rx_buffer[i]= 0;

return U0RBR;

if(ch ==0x0A){
   VICIntEnable &= (~0x00020000);
   eventMarker=1;
   ch=0;
}

else if (ch ==0x0B){
    shutdown();
  ch=0;
  }
else if (ch ==0x0C){
blink(1,ON);
 ch=0;
 }

else if (ch ==0x0D){
blink(1,OFF);   
    ch=0;
}

VICIntEnable |= 0x00024000;
VICVectAddr= 0;
U0IER = 0x00; 

}
Oli Glaser
  • 54,990
  • 3
  • 76
  • 147
serendipity
  • 151
  • 4

2 Answers2

1

Nothing happens because nothing beyond the

return U0RBR;

in the ISR gets executed. All of your conditionals that could do something are in the dead code following the unconditional return.

Likely you need to rethink the architecture of your program, particularly the relationship between the ISR and the main program loop - there are advantages and disadvantages to doing command processing in either place.

Chris Stratton
  • 33,282
  • 3
  • 43
  • 89
0

Do this and you'll be able to fix it, probably :-).

  • While that code is not complex, best debugging results are usually achieved by removing EVERYTHING that is not considered essential

  • and, by then changing as little as possible during the course of execution.

Here eg If sending or receiving characters is in question,

  • Send a single character with suitable pauses between.

  • If you can do with only one test or loop or conditional-whatever then only have the one.

  • Once the utterly trivial works you can add to it.

  • If the utterly trivial fails it makes it a lot easier to spot the bad assumptions or actions or hardware.

Russell McMahon
  • 147,325
  • 18
  • 210
  • 386