Quantcast
Channel: Microcontrollers
Viewing all articles
Browse latest Browse all 229107

Forum Post: Comunication Master SPI Launchpad MSP430

$
0
0

good morning, I'm trying to make a master-slave communication with Launchpad msp430g2553 card and this is the code that I have for the teacher (please help if the code has errors)

#include "msp430g2553.h"

#define LED0 BIT0
#define LED1 BIT6
#define CS BIT7
#define BUTTON BIT3

unsigned int i=0;
//#define RX BIT7

unsigned char MST_Data, SLV_Data;
//unsigned int i;
//unsigned int j=0x00;

//void Prueba(void){
//P1DIR |= (LED0 + LED1); // Set P1.0 to output direction
//P1OUT = 0x01; // set P1.0 to 0 (LED OFF)
//for(i=0;i<=5;i++){
//P1OUT ^= (LED0 + LED1);
//__delay_cycles(100000);
//}
//P1OUT =0x00;
//}

void ConfigBoton(){

P1DIR |= (LED0 + LED1); // Set P1.0 to output direction
// P1.3 must stay at input
P1OUT &= ~(LED0 + LED1); // set P1.0 to 0 (LED OFF)
P1OUT &=~ CS;
P1IE |= BUTTON; // P1.3 interrupt enabled
P1REN |=BUTTON;
P1IES |= BUTTON;
P1IFG &= ~BUTTON; // P1.3 IFG cleared
__bis_SR_register(LPM0_bits + GIE);
//__bis_SR_register(LPM0_bits + GIE);
//__enable_interrupt();
}

void ConfigMasterSPI(void){

P1DIR |= BIT0 + BIT5 + BIT6; //Bit0,5 y 6 output
P1SEL |= BIT2 + BIT4; //Bit1,2 y 4 SPI config
P1SEL2 |= BIT2 + BIT4; //Low output Port1
UCA0CTL0 |= UCCKPL + UCMSB + UCMST + UCSYNC; //SPI Config: Clock polarity low, MSB First, 8 bits, Master, Synchronous mode
UCA0CTL1 |= UCSSEL_2; //Clock source select
UCA0CTL1 &=~ UCSWRST; //Disable reset release for operation
UCA0BR0 = 0x02; //Frecuency div
UCA0BR1 = 0x00;
UCA0MCTL = 0x00; //Disable modulation
IE2 |= UCA0TXIE; //Enable interrupt TX
IFG2 &=~ UCA0TXIFG; //Clear Flag TX
P1OUT =0x00; //Now with SPI signals initialized,
__delay_cycles(75); //espera para inicializar el esclavo
//UCA0RXBUF = 0x00;
MST_Data = 0x01; // Data to Transmit
UCA0TXBUF = MST_Data;
}

//Main Funtion

int main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer // Set P1.7 input low
ConfigBoton(); // Set USCI Master Mode
while(1)
{
}
}


#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT ^= ( LED0);
ConfigMasterSPI();

while(1)
{
if(P1IN & BIT7){

while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready

MST_Data++; // Increment master value
//SLV_Data++; // Increment expected slave value
UCA0TXBUF = MST_Data; // Send next value
__delay_cycles(50);
}
}

P1IFG &=~ BUTTON;
//__bic_SR_register_on_exit(LPM0_bits);
}/

and with respect to this program I have several questions:

when this program was downloaded to the card, there are times
that disruption of the push button works, and there
other times that it does as it should. already
active IE and pull up?

Why the master clock signal is not generated when
this is not transmitting any data?

UCA0RXIFG why the flag is set each time I transfer
a data to transmit buffer UCA0TXBUFF, if only
I SIMO mode active?

Because sometimes when I download the program to the card,
sometimes work properly, and sometimes not? I have the latest
CCS version 5.5 and windows7? compiler?

and when should I use __ bis_SR_register (LPM0_bits + GIE) and when
__enable_interrupt?

Thank you very much for your help.


Viewing all articles
Browse latest Browse all 229107

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>