Hi,
I am facing a little problem with the bluetooth communication with my MSP430F479. I am using the BM70 ble module. I am trying to send two words over the transmit pin and as the buffer can only contain one byte, I am sending the Upper byte first and then the lower byte by swapping. The received first byte in the mobile app (to see the bluetooth transmitted data) is always correct that is as sent by the TX pin (using a breakpoint after each transmit to check the received byte). But for the second byte and third byte data transmitted, I am not getting the right data (it is showing wrong byte of data in the app) . The UART baud rate of the MSP430 is set 115200 Hz as the default baud rate of the BM70 ble module is also the same. I am attaching the code simulated in the IAR embedded workbench below:
#include <msp430.h> ;------------------------------------------------------------------------------- ORG 01100h ; Program Start ;----------------------------------------------------------------------------- RESET mov.w #0A00h,SP ; Initialize stackpointer StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT SetupFLL bis.b #XCAP11PF,&FLL_CTL0 ; Configure load caps SetupP1 bis.b #03h,&P1DIR ; P1.1 and P1.2 output (LD1 output set to make the BM70 in application mode) bis.b #03h,&P1OUT OFIFGcheck bic.b #OFIFG,&IFG1 ; Clear OFIFG mov.w #047FFh,R15 ; Wait for OFIFG to set again if OFIFGwait dec.w R15 ; not stable yet jnz OFIFGwait bit.b #OFIFG,&IFG1 ; Has it set again? jnz OFIFGcheck ; If so, wait some more SetupP2 bis.b #BIT4+BIT5,&P2SEL ; P2.4,5 USCI option select SetupUART bis.b #UCSSEL_2,&UCA0CTL1 ; SMCLK mov.b #09,&UCA0BR0 ; 1MHz 115200 mov.b #00,&UCA0BR1 ; 1MHz 115200 mov.b #02,&UCA0MCTL ; Modulation bic.b #UCSWRST,&UCA0CTL1 ; **Initialize USCI state machine** bis.b #UCA0RXIE,&IE2 ; Enable USCI_A0 RX interrupt Mainloop mov.w #0F349h,R7 ;data to be sent mov.w #1234h,R6 ;data to be sent TZ1 bit.b #UCA0TXIFG,&IFG2 ; USCI_A0 TX buffer ready? jz TZ1 ; Jump if TX buffer not ready swpb R7 ;swapping the bytes mov.b R7, &UCA0TXBUF ;send most significant byte swpb R6 ; Prepare to send High Byte of Sum TZ2 bit.b #UCA0TXIFG,&IFG2 ; USCI_A0 TX buffer ready? jz TZ2 ; Jump if TX buffer not ready mov.b R6, &UCA0TXBUF ; Send High Byte of Sum swpb R6 TZ3 bit.b #UCA0TXIFG,&IFG2 ; USCI_A0 TX buffer ready? jz TZ3 ; Jump if TX buffer not ready swpb R6 mov.b R6, &UCA0TXBUF ; Send Low Byte of sum LEND bis.b #LPM3+GIE,SR ; Enter LPM3, interrupts enabled nop ;------------------------------------------------------------------------------ USCIA0RX_ISR; Echo back RXed character, confirm TX buffer is ready first ;------------------------------------------------------------------------------ TX0 bit.b #UCA0TXIFG,&IFG2 ; USCI_A0 TX buffer ready? jz TX0 ; Jump if TX buffer not ready ;mov.b &UCA0RXBUF,&UCA0TXBUF ; TX -> RXed character bic.w #LPM3,0(SP) ; Turn the CPU back on reti ; ; ;------------------------------------------------------------------------------ ; Interrupt Vectors ;------------------------------------------------------------------------------ ORG 0FFFEh ; RESET Vector DW RESET ; ORG 0FFF2h ; USCI_A0 Rx Vector DW USCIA0RX_ISR ; END
Sample output:
First output (Expected F3):
Second output (Expected 12):
Third output (Expected 34):
Can you please help me how to solve this and sorry for the long post. Thanks in advance.