Hi,
I'm having a hell of a time trying to figure out how to correctly connect my 2231 to my Emmoco EDB-BLE board. I know the cabling is correct as per this picture: http://dev2.emmoco.com:8090/display/em/Using+MSP430+LaunchPad+Rev.1.4
I am trying to parse through the code that Emmoco generates in order to adapt it for my own msp. I am doing this by looking at both header files and trying to figure out what is equivalent in the 2231.h to the original code. This is their code for the blinker program:
/*
* ============ Platform Configuration ============
*/
#include<msp430.h>
#define LED_ON() (P1OUT |= BIT6)
#define LED_OFF() (P1OUT &= ~BIT6)
#define LED_READ() (P1OUT & BIT6)
#define LED_TOGGLE() (P1OUT ^= BIT6)
#define CONNECTED_LED_ON() (P1OUT |= BIT0)
#define CONNECTED_LED_OFF() (P1OUT &= ~BIT0)
#define EAP_RX_BUF UCA0RXBUF
#define EAP_TX_BUF UCA0TXBUF
#define EAP_RX_VECTOR USCIAB0RX_VECTOR
#define EAP_TX_VECTOR PORT2_VECTOR
#define EAP_RX_ACK_CONFIG() (P2DIR |= BIT0)
#define EAP_RX_ACK_SET() (P2OUT |= BIT0)
#define EAP_RX_ACK_CLR() (P2OUT &= ~BIT0)
#define EAP_TX_INT_CONFIG() (P2DIR &= ~BIT1, P2IES |= BIT1, P2IFG &= BIT1, P2IE |= BIT1)
#define EAP_TX_INT_TST() (P2IFG & BIT1)
#define EAP_TX_INT_CLR() (P2IFG &= ~BIT1)
void init(void) {
WDTCTL = WDTPW + WDTHOLD;
BCSCTL2 = SELM_0 + DIVM_0 + DIVS_0;
if (CALBC1_1MHZ != 0xFF) {
DCOCTL = 0x00;
BCSCTL1 = CALBC1_1MHZ; /* Set DCO to 1MHz */
DCOCTL = CALDCO_1MHZ;
}
BCSCTL1 |= XT2OFF + DIVA_0;
BCSCTL3 = XT2S_0 + LFXT1S_2 + XCAP_1;
P1DIR |= BIT0; /* LED */
LED_OFF();
P1DIR |= BIT6; /* CONNECTED_LED */
CONNECTED_LED_OFF();
UCA0CTL1 |= UCSWRST;
P1SEL |= BIT1 + BIT2;
P1SEL2 |= BIT1 + BIT2;
EAP_RX_ACK_CONFIG();
EAP_RX_ACK_SET();
EAP_TX_INT_CONFIG();
UCA0CTL1 = UCSSEL_2 + UCSWRST;
UCA0MCTL = UCBRF_0 + UCBRS_6;
UCA0BR0 = 8;
UCA0CTL1 &= ~UCSWRST;
IFG2 &= ~(UCA0RXIFG);
IE2 |= UCA0RXIE;
TA1CCTL0 = CM_0 + CCIS_0 + OUTMOD_0 + CCIE;
TA1CCR0 = 1200;
TA1CTL = TASSEL_1 + ID_0 + MC_1;
__enable_interrupt();
}
/*
* ============ Serial Driver ============
*/
#include<Em_Message.h>
__attribute__((interrupt(EAP_RX_VECTOR)))
staticvoid rxHandler(void) {
uint8_t b = EAP_RX_BUF;
if (Em_Message_addByte(b)) {
Em_Message_dispatch();
}
EAP_RX_ACK_CLR();
EAP_RX_ACK_SET();
}
__attribute__((interrupt(EAP_TX_VECTOR)))
staticvoid txHandler(void) {
if (EAP_TX_INT_TST()) {
uint8_t b;
if (Em_Message_getByte(&b)) {
EAP_TX_BUF = b;
}
EAP_TX_INT_CLR();
}
}
void Em_Message_startSend() {
uint8_t b;
if (Em_Message_getByte(&b)) {
UCA0TXBUF = b;
}
}
uint8_t Em_Message_lock() {
uint8_t key;
asm ("MOV r2, %0": "=r" (key));
key &= 0x8;
asm ("DINT");
return key;
}
void Em_Message_unlock(uint8_t key) {
if (key) {
asm ("EINT");
}
else {
asm ("DINT");
}
}
/*
* ============ Application Program ============
*/
#include<Blinker.h>
#define COUNT_DEFAULT 5
volatile Blinker_cmd_t cmdRes = Blinker_STOP_CMD;
volatile Blinker_count_t countRes = COUNT_DEFAULT;
volatile Blinker_delay_t delayRes = Blinker_delay_min;
volatile Blinker_count_t curCount;
volatile Blinker_delay_t curTime;
__attribute__((interrupt(TIMER1_A0_VECTOR)))
void tickHandler(void) {
if (cmdRes == Blinker_STOP_CMD) {
return;
}
if (curTime < delayRes) {
curTime += Blinker_delay_step;
return;
}
else {
curTime = 0;
}
if (curCount-- > 0) {
LED_TOGGLE();
}
else {
cmdRes = Blinker_STOP_CMD;
LED_OFF();
}
Blinker_ledState_indicate();
}
int main(int argc, char *argv[]) {
volatile int dummy = 0;
init();
Blinker_run();
while (dummy == 0) {
/* idle */
}
return 0;
}
void Blinker_connectHandler(void) {
CONNECTED_LED_ON();
}
void Blinker_disconnectHandler(void) {
CONNECTED_LED_OFF();
}
void Blinker_cmd_store(Blinker_cmd_t* input) {
cmdRes = *input;
switch (cmdRes) {
case Blinker_START_CMD:
curCount = countRes * 2;
curTime = 0;
break;
case Blinker_STOP_CMD:
LED_OFF();
break;
}
}
void Blinker_count_fetch(Blinker_count_t* output) {
*output = countRes;
}
void Blinker_count_store(Blinker_count_t* input) {
countRes = *input;
}
void Blinker_delay_fetch(Blinker_delay_t* output) {
*output = delayRes;
}
void Blinker_delay_store(Blinker_delay_t* input) {
delayRes = *input;
}
void Blinker_ledState_fetch(Blinker_ledState_t* output) {
*output = LED_READ() ? Blinker_LED_ON : Blinker_LED_OFF;
}
Here's the thing - the launchpad that I have does not seem to have a USI modulation control register. So I don't know what to do with the line
UCA0MCTL = UCBRF_0 + UCBRS_6;
Also, there are no comments, so I have no way of knowing what is going on in each line, or why.
I would appreciate immediate help! I am a software dev and I feel extremely out of my depth here!
EDIT: Here is the code I have up to now. Notice the commented out lines where the original code deals with the USCI Modulation.
/*
* ============ Platform Configuration ============
*/
#include<msp430.h>
#define LED_ON() (P1OUT |= BIT6)
#define LED_OFF() (P1OUT &= ~BIT6)
#define LED_READ() (P1OUT & BIT6)
#define LED_TOGGLE() (P1OUT ^= BIT6)
#define CONNECTED_LED_ON() (P1OUT |= BIT0)
#define CONNECTED_LED_OFF() (P1OUT &= ~BIT0)
#define EAP_RX_BUF USISRL
#define EAP_TX_BUF USISRH
#define EAP_RX_VECTOR USI_VECTOR
#define EAP_TX_VECTOR PORT2_VECTOR
#define EAP_RX_ACK_CONFIG() (P2DIR |= BIT0)
#define EAP_RX_ACK_SET() (P2OUT |= BIT0)
#define EAP_RX_ACK_CLR() (P2OUT &= ~BIT0)
#define EAP_TX_INT_CONFIG() (P2DIR &= ~BIT1, P2IES |= BIT1, P2IFG &= BIT1, P2IE |= BIT1)
#define EAP_TX_INT_TST() (P2IFG & BIT1)
#define EAP_TX_INT_CLR() (P2IFG &= ~BIT1)
void init(void) {
WDTCTL = WDTPW + WDTHOLD;
BCSCTL2 = SELM_0 + DIVM_0 + DIVS_0; // Setting basic clock system
if (CALBC1_1MHZ != 0xFF) {
DCOCTL = 0x00;
BCSCTL1 = CALBC1_1MHZ; /* Set DCO to 1MHz */
DCOCTL = CALDCO_1MHZ;
}
BCSCTL1 |= XT2OFF + DIVA_0;
BCSCTL3 = XT2S_0 + LFXT1S_2 + XCAP_1;
P1DIR |= BIT0; /* LED */
LED_OFF();
P1DIR |= BIT6; /* CONNECTED_LED */
CONNECTED_LED_OFF();
USICTL1 |= USISWRST;
P1SEL |= BIT1 + BIT2;
//P1SEL2 |= BIT1 + BIT2;
EAP_RX_ACK_CONFIG();
EAP_RX_ACK_SET();
EAP_TX_INT_CONFIG();
USICTL1 = USISSEL_3 + USISWRST;
// UCA0MCTL = UCBRF_0 + UCBRS_6;
// UCA0BR0 = 8;
USICTL1 &= ~USISWRST;
IFG1 &= ~(USIIFG);
IE1 |= USIIE;
TACCTL0 = CM_0 + CCIS_0 + OUTMOD_0 + CCIE;
TACCR0 = 1200;
TACTL = TASSEL_1 + ID_0 + MC_1;
__enable_interrupt();
}
/*
* ============ Serial Driver ============
*/
#include<Em_Message.h>
__attribute__((interrupt(EAP_RX_VECTOR)))
staticvoid rxHandler(void) {
uint8_t b = EAP_RX_BUF;
if (Em_Message_addByte(b)) {
Em_Message_dispatch();
}
EAP_RX_ACK_CLR();
EAP_RX_ACK_SET();
}
__attribute__((interrupt(EAP_TX_VECTOR)))
staticvoid txHandler(void) {
if (EAP_TX_INT_TST()) {
uint8_t b;
if (Em_Message_getByte(&b)) {
EAP_TX_BUF = b;
}
EAP_TX_INT_CLR();
}
}
void Em_Message_startSend() {
uint8_t b;
if (Em_Message_getByte(&b)) {
USISRH = b;
}
}
uint8_t Em_Message_lock() {
uint8_t key;
asm ("MOV r2, %0": "=r" (key));
key &= 0x8;
asm ("DINT");
return key;
}
void Em_Message_unlock(uint8_t key) {
if (key) {
asm ("EINT");
}
else {
asm ("DINT");
}
}
/*
* ============ Application Program ============
*/
#include<Blinker.h>
#define COUNT_DEFAULT 5
volatile Blinker_cmd_t cmdRes = Blinker_STOP_CMD;
volatile Blinker_count_t countRes = COUNT_DEFAULT;
volatile Blinker_delay_t delayRes = Blinker_delay_min;
volatile Blinker_count_t curCount;
volatile Blinker_delay_t curTime;
__attribute__((interrupt(TIMERA0_VECTOR)))
void tickHandler(void) {
if (cmdRes == Blinker_STOP_CMD) {
return;
}
if (curTime < delayRes) {
curTime += Blinker_delay_step;
return;
}
else {
curTime = 0;
}
if (curCount-- > 0) {
LED_TOGGLE();
}
else {
cmdRes = Blinker_STOP_CMD;
LED_OFF();
}
Blinker_ledState_indicate();
}
int main(int argc, char *argv[]) {
volatile int dummy = 0;
init();
Blinker_run();
while (dummy == 0) {
/* idle */
}
return 0;
}
void Blinker_connectHandler(void) {
CONNECTED_LED_ON();
}
void Blinker_disconnectHandler(void) {
CONNECTED_LED_OFF();
}
void Blinker_cmd_store(Blinker_cmd_t* input) {
cmdRes = *input;
switch (cmdRes) {
case Blinker_START_CMD:
curCount = countRes * 2;
curTime = 0;
break;
case Blinker_STOP_CMD:
LED_OFF();
break;
}
}
void Blinker_count_fetch(Blinker_count_t* output) {
*output = countRes;
}
void Blinker_count_store(Blinker_count_t* input) {
countRes = *input;
}
void Blinker_delay_fetch(Blinker_delay_t* output) {
*output = delayRes;
}
void Blinker_delay_store(Blinker_delay_t* input) {
delayRes = *input;
}
void Blinker_ledState_fetch(Blinker_ledState_t* output) {
*output = LED_READ() ? Blinker_LED_ON : Blinker_LED_OFF;
}