Communication between two MSP430 with using UART (MSP430 Application C ++)
Hello guys,
This tutorial shows you how to communicate between two MSPs. Firstly, one of them must be a master controller. And the other remaining one must be slaves. Basically , when you enter some input from master contoller, A signal comes from master, goes into slave's input.
This tutorial is show us when you press button from master controller, other controller led will light up.
Embed the codes into microcontroller separately.
Play the code as you wish. Mail me if there are any problems with code.
Mail: g.haddeler@gmail.com
You all succeed!
-------------------------
MASTER MSP430 CODES
#include "msp430g2553.h"
// When you press buton , data which is 0x01 , sends it to slave msp via UART . As long as the data coming from master msp is equal to '2' , the master msp's led lights up.
// function prototypes
void UARTInit(void);
void main(void){
WDTCTL = WDTPW + WDTHOLD;// watchdog timer OFF
//DCO clock freq settings
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
UARTInit();// UART settings are called.
P1DIR = 0x41;//P1.3 input, P1.0 & P1.6 output
P1OUT = 0x00; // Clearing output data.
__bis_SR_register(GIE);//interrupts are active
while(1){
if(!(P1IN&BIT3)){
UCA0TXBUF = 0x01;
__delay_cycles(100000);//Waiting for 2 seconds because we woring with 8MHZ
}
else
if(UCA0RXBUF==2){
P1OUT =0x40;
__delay_cycles(100000);}
}
}
//UART Settings
void UARTInit(void){
P1SEL |= (BIT1 + BIT2);//P1.1 = RXD P1.2 = TXD
P1SEL2 |= (BIT1 + BIT2);//P1.1 = RXD P1.2 = TXD
UCA0CTL1 = UCSSEL_2; // clock source SMCLK
//UCOS16 = 1 Baudrate Settings
UCA0BR0 = 52;
UCA0BR1 = 0;
//Modulator settings
UCA0MCTL = 0x11;// By the formula
UCA0CTL1 &= ~UCSWRST; // UCSWRT register cleared for USCI operation .
IE2 |= UCA0RXIE; // RXD interrupt enabled
}
--------------------------------------------------
SLAVE MSP CODES
#include<msp430g2553.h>
// if the incoming data is equal to 0x01 , led will be on , else it will off.
// function prototypes
void UARTInit(void);
void a(unsigned char c);
void main(void){
WDTCTL = WDTPW + WDTHOLD;// watchdog timer OFF
//DCO clock freq settings
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
UARTInit();//UART settings are called.
P1DIR = 0x41;//P1.3 input, P1.0 & P1.6 output
P1OUT = 0x00; // Clearing output data.
__bis_SR_register(GIE);//interrupts are active
while(1){
if( UCA0RXBUF==0x01){
P1OUT = 0x01;
__delay_cycles(100000); }// waiting 2 seconds because we are working with 8 MHz
UCA0TXBUF =2;
}
}
//UART SETTİNGS
void UARTInit(void){
void UARTInit(void){
P1SEL |= (BIT1 + BIT2);//P1.1 = RXD P1.2 = TXD
P1SEL2 |= (BIT1 + BIT2);//P1.1 = RXD P1.2 = TXD
UCA0CTL1 = UCSSEL_2; // clock source SMCLK
//UCOS16 = 1 Baudrate settings
UCA0BR0 = 52;
UCA0BR1 = 0;
//Modulator settings
UCA0MCTL = 0x11;//by the formula
UCA0CTL1 &= ~UCSWRST; // UCSWRT register cleared for USCI operation .
IE2 |= UCA0RXIE; // RXD interrupt enabled
}}
Yorumlar
Yorum Gönder