Part Number:MSP430FR2433
So basically here is the layout. I have one Master HC-05 Bluetooth Module connected to one MSP with a joystick, the other has the Slave.
Here is the code for the Master HC-05 MSP
FIRST MSP CODE
#include "msp430.h" ; #define controlled include file
NAME main ; module name
PUBLIC main ; make the main label vissible
; outside this module
ORG 0FFFEh
DC16 init ; set reset vector to 'init' label
RSEG CSTACK ; pre-declaration of segment
RSEG CODE ; place program in 'CODE' segment
RSEG DATA16_N
TXData DW 0h
Voltage DW 0h
init: MOV #SFE(CSTACK), SP ; set up stack
main: NOP ; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
;18:E4:35F093 <-- Bluetooth Address
;Ports
bis.b #BIT0, P1DIR
bic.b #BIT0, P1OUT
;Push Button Setup
BIS.B #BIT7, &P2REN ;P2.7 Pullup or Pulldown register enabled
BIS.B #BIT7, &P2OUT ;P2.7 Set as Pulldown register
BIS.B #BIT7, &P2IES ;P2.7 Lo/Hi edge enabled
BIC.B #BIT7, &P2IFG ;P2.7 IFG cleared
;Setup Clock
bis.w #SCG0, SR
bis.w #SELREF__REFOCLK, &CSCTL3 ;Creates reference for Clock Source = REFOCLK
mov.w #0, &CSCTL0
bic.w #DCORSEL_7, &CSCTL1 ; Clear data @ CSCTL1
bis.w #DCORSEL_0, &CSCTL1 ;Set DCO for 1 MHZ Operation
mov.w #FLLD_0+30, &CSCTL2 ;FLLD+30 = FLLD for 1mhz DCO
bic.w #SCG0, SR
;Setup ADC
mov.w #ADCPCTL1, &SYSCFG2
bic.w #LOCKLPM5, PM5CTL0
mov.w #ADCSHT_2|ADCON, &ADCCTL0
bis.w #ADCSHP, &ADCCTL1
bis.w #ADCRES, &ADCCTL2
bis.w #ADCINCH_1, &ADCMCTL0
bis.w #ADCIE0, &ADCIE
unlockFLL:
mov.w &CSCTL7, R13
and.w #FLLUNLOCK0|FLLUNLOCK1, R13
jnz unlockFLL
mov.w #SELMS__DCOCLKDIV+SELA__REFOCLK, &CSCTL4
bic.w #LOCKLPM5,PM5CTL0
;Setup Uart
bis.b #BIT4+BIT5, &P1SEL0
bis.w #UCSWRST, &UCA0CTLW0
bis.w #UCSSEL__SMCLK,&UCA0CTLW0
mov.b #104, UCA0BR0
clr.b &UCA0BR1
bis.w #UCBRS0, &UCA0MCTLW
bic.w #UCSWRST, &UCA0CTLW0
MainLoop:
bis.w #ADCENC|ADCSC, &ADCCTL0
nop
bis.w #LPM3+GIE, SR
nop
cmp #250h, Voltage
jhs L2
cmp #01ffh,Voltage
jl L3
bic.b #BIT0, &P1OUT
jmp MainLoop
bit.w #0x03, TXData
call #Send_Data
jmp MainLoop
L3:
bit.w #0x01, TXData
xor.b #BIT0, P1OUT
call #Send_Data
jmp MainLoop
L2:
bit.w #0x02, TXData
xor.b #BIT0, P1OUT
call #Send_Data
jmp MainLoop
ADC_ISR:
mov.w &ADCMEM0, Voltage
bic.w #LPM3, 0(SP)
reti
Send_Data:
cmp.w #0x1, &UCTXIFG
jz Send_Data
mov.w TXData, &UCA0TXBUF
ret
COMMON INTVEC
ORG ADC_VECTOR
DW ADC_ISR
END
SECOND MSP Code
Here is the code for my Slave MSP
#include "msp430.h" ; #define controlled include file
NAME main ; module name
PUBLIC main ; make the main label vissible
; outside this module
ORG 0FFFEh
DC16 init ; set reset vector to 'init' label
RSEG CSTACK ; pre-declaration of segment
RSEG CODE ; place program in 'CODE' segment
RSEG DATA16_N
RXData DW 0h
init: MOV #SFE(CSTACK), SP ; set up stack
main: NOP ; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
;18:E4:35F093 <-- Bluetooth Address
;Ports
bis.b #BIT0, P1DIR
bic.b #BIT0, P1OUT
;Relay Ports
;Forward
;Front
bis.b #BIT0, P2DIR
bis.b #BIT1, P2DIR
bis.b #BIT0, P2OUT
bic.b #BIT1, P2OUT
;Back
bis.b #BIT5, P2DIR
bis.b #BIT6, P2DIR
bis.b #BIT5, P2OUT
bic.b #BIT6, P2OUT
;Backward
;Front
bis.b #BIT0, P2DIR
bis.b #BIT1, P2DIR
bis.b #BIT1, P2OUT
bic.b #BIT0, P2OUT
;Back
bis.b #BIT5, P2DIR
bis.b #BIT6, P2DIR
bis.b #BIT6, P2OUT
bic.b #BIT5, P2OUT
bis.w #SCG0, SR
bis.w #SELREF__REFOCLK, &CSCTL3 ;Creates reference for Clock Source = REFOCLK
mov.w #0, &CSCTL0
bic.w #DCORSEL_7, &CSCTL1 ; Clear data @ CSCTL1
bis.w #DCORSEL_0, &CSCTL1 ;Set DCO for 1 MHZ Operation
mov.w #FLLD_0+30, &CSCTL2 ;FLLD+30 = FLLD for 1mhz DCO
nop
nop
nop
bic.w #SCG0, SR
unlockFLL:
mov.w &CSCTL7, R13
and.w #FLLUNLOCK0|FLLUNLOCK1, R13
jnz unlockFLL
mov.w #SELMS__DCOCLKDIV+SELA__REFOCLK, &CSCTL4
bic.w #LOCKLPM5,PM5CTL0
bis.b #BIT4+BIT5, &P1SEL0
bis.w #UCSWRST, &UCA0CTLW0
bis.w #UCSSEL__SMCLK,&UCA0CTLW0
mov.b #104, UCA0BR0
clr.b &UCA0BR1
bis.w #UCBRS0, &UCA0MCTLW
bic.w #UCSWRST, &UCA0CTLW0
clr.w RXData
bis.w #UCRXIE, &UCA0IE
nop
bis.w #LPM3+GIE,SR
nop
USC_ISR:
mov.w &UCA0RXBUF, RXData
bic.w #UCRXIFG, &UCA0IFG
xor.b #BIT0, P1OUT
reti
COMMON INTVEC
org USCI_A0_VECTOR
dw USC_ISR
END
I can get it to transmit whenever I toggle a Joystick and toggle the light, but I am getting some funky data. I tried to transfer only #0x01, but am getting like 255 on the other end. Any suggestions on how to fix this?