Hello!
I just figured out how to make a SPI link to work in a way that just the Master MCU sends out an 8 bit valeu to the Slave MCU.
But know, what I'm looking forward to do is to make them both send and recieve 8 bits values.
Well I tried to do it with no sucess. I would like to know what steps I need to take in order to make it work.
Here is my code for both the Master and Slave MCUs in wich the masters sends out a value and the slave recieves it.
MSP430 G2553 (SLAVE)
#include <msp430.h>
volatile unsigned char RECEP = 0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0x40;
P1SEL = 0x40;
TACCR0 = 255;
TACCTL1 = OUTMOD_7;
TACCR1 = 0;
TACTL = TASSEL_2 + MC_1;
P1DIR |= BIT0;
P1OUT &= ~BIT0;
P1SEL |= BIT1 + BIT2 + BIT4;
P1SEL2 |= BIT1 + BIT2 + BIT4;
UCA0CTL0 |= UCCKPL + UCMSB + UCSYNC;
UCA0CTL1 &= ~UCSWRST;
IE2 |= UCA0RXIE;
__bis_SR_register(GIE);
while(1){
TACCR1 = RECEP;
IE2 |= UCA0RXIE;}
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIA0RX_ISR(void)
{
P1OUT ^= BIT0;
RECEP = UCA0RXBUF;
}
MSP430 FR5739 (MASTER) code:
#include <msp430.h>
unsigned char TXData;
volatile unsigned char a =0;
int main(void)
{
WDTCTL = WDTPW+WDTHOLD;
P3DIR |= BIT4;
P3OUT |= BIT4;
P1SEL1 |= BIT5;
P2SEL1 |= BIT0 + BIT1;
UCA0CTLW0 |= UCSWRST;
UCA0CTLW0 |= UCMST+UCSYNC+UCCKPL+UCMSB;
UCA0CTLW0 |= UCSSEL_2;
UCA0BR0 = 0x16;
UCA0BR1 = 0;
UCA0MCTLW = 0;
UCA0IE |= UCRXIE;
UCA0CTLW0 &= ~UCSWRST;
TXData = 0;
//TIMER_B2 CONFIGURATION
P3DIR |= BIT6 + BIT7;
P3SEL0 |= BIT6 + BIT7;
TB2CCTL1 = OUTMOD_7;
TB2CCTL2 = OUTMOD_7;
TB2CCR0 = 256;
TB2CCR1 = 0;
TB2CCR2 = 0;
TB2CTL = TBSSEL_2 + MC_1;
while(1){
UCA0IE |= UCTXIE;
__bis_SR_register(GIE);
__no_operation();
__delay_cycles(80000);
if( a < 256 ){
a += 2;
TXData++;
TB2CCR1 = TXData;
TB2CCR2 = TXData;}
else{
a=0;
TXData = 0;}
}}
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,0x04))
{
case 0: break;
case 2: break;
case 4:
P3OUT ^= BIT4;
UCA0TXBUF = TXData;
UCA0IE &= ~UCTXIE;
break;
default: break;
}}