This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
1) HERE in master microcontroller if pin0 of port 2 is disconnected then the mster(msp 430) will transmit only (0x01) to the slave(msp432) and the led will toggle at port 2.0 at msp432 .
2) HERE in master microcontroller if pin1 of port 2 is disconnected then the mster(msp 430) will transmit only (0x02) to the slave(msp432) and the led will toggle at port 1.0 at msp432 .
the program is working properly but my problem is the led blink is continous ..i want my led to blink only once as soon as the pin is disconnected(any in case 1 pin0, in case 2 pin 1)
3) plz help me,,,i think i can use interrupt ..but not sure ..u can help me with different alternative as well.
#include <msp430.h>
volatile char received_ch = 0;
int main(void)
{
//P1OUT |= BIT5;
P1SEL = BIT0 | BIT2 | BIT4;
P1SEL2 = BIT0 | BIT2 | BIT4;
UCA0CTL1 = UCSWRST;
UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 |= 0x01; // /2
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0TXIE; // Enable USCI0 RX interrupt
// P1OUT &= (~BIT5); // Select Device
__bis_SR_register(LPM0_bits + GIE); // CPU off, enable interrupts
// P1OUT |= (BIT5); // Unselect Device
}
//------------------------------------------------------------------------------------------------
// Test for valid RX and TX character
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCIA0TX_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCIAB0TX_VECTOR))) USCIA0TX_ISR (void)
#else
#error Compiler not supported!
#endif
{
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
{
if ((0X01 & P2IN)) // AS led1 is (0x01) i.e (0000 0001) 8 bit , as 2v supply is our constant
{ //input all input pins are high we AND it with P2IN thus if input is set
P1OUT &= ~ 0x01;
}
else
{
UCA0TXBUF = 0x01; // Send over SPI to Slave
__delay_cycles(50); // Add time between transmissions to
}
if ((0X02 & P2IN)) // AS led1 is (0x01) i.e (0000 0001) 8 bit , as 2v supply is our constant
{ //input all input pins are high we AND it with P2IN thus if input is set
P1OUT &= ~ 0x01; // stop the output buzzer (perform no action)
}
else
{
UCA0TXBUF = 0x02; // Send over SPI to Slave
__delay_cycles(50);
}
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*****************************************************************************
* msp 432 slave
* ids system
* pin connection
* MSP430g2553 Master MSP432P401x Slaves
// ----------------- -----------------
// /|\| | /|\| |
// | | | | | |
// --|RST | --|RST |
// | | | |
// | | Data In (UCB0SIMO) | |
// | P1.0|------------------->|P1.6 |
// | | | |
// | | Data OUT (UCB0SOMI)| |
// | P1.2|<-------------------|P1.7 |
// | | | |
// | | S Clock (UCB0CLK) | |
// | P1.4|------------------->|P1.5 |
// | | | |
//
*****************************slave program is*************************************************/
#include "msp.h"
volatile unsigned int RXData,w;
int main(void)
{
WDT_A->CTL = WDT_A_CTL_PW | // Stop watchdog timer
WDT_A_CTL_HOLD;
P2->DIR |= BIT0; // P2.0 set as output
P1->SEL0 |= BIT5 | BIT6 | BIT7; // Set P1.5, P1.6, and P1.7 as
// SPI pins functionality
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_SWRST; // Put state machine in reset
EUSCI_B0->CTLW0 = EUSCI_B_CTLW0_SWRST | // Keep the state machine in reset
EUSCI_B_CTLW0_SYNC | // Set as synchronous mode
EUSCI_A_CTLW0_CKPL | // Set clock polarity high
EUSCI_B_CTLW0_MSB; // MSB first and Slave
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_SSEL__ACLK; // ACLK
EUSCI_B0->BRW = 0x02; // /2,fBitClock = fBRCLK/(UCBRx+1).
EUSCI_B0->CTLW0 &= ~EUSCI_B_CTLW0_SWRST;// Initialize USCI state machine
EUSCI_B0->IE |= EUSCI_B_IE_RXIE; // Enable USCI_B0 RX interrupt
// Enable global interrupt
__enable_irq();
// Enable eUSCI_B0 interrupt in NVIC module
NVIC->ISER[0] = 1 << ((EUSCIB0_IRQn) & 31);
__sleep();
__no_operation();
// Remain in LPM on exit from ISR
// SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
// Ensures SLEEPONEXIT takes effect immediately
/// __DSB();
}
//------------------------------------------------------------------------------------
// SPI interrupt service routine
void EUSCIB0_IRQHandler(void)
{
// Wait till a character is received
while (!(EUSCI_B0->IFG & EUSCI_B_IFG_RXIFG));
RXData = EUSCI_B0->RXBUF;
if (RXData==0x01)
{
P2->OUT ^= BIT0; // XOR P1.0
for (w = 20000; w > 0; w--); // Delay
}
if (RXData==0x02)
{
P1->OUT ^= BIT0; // XOR P1.0
for (w = 20000; w > 0; w--); // Delay
}
// Clear the receive interrupt flag
EUSCI_B0->IFG &= ~EUSCI_B_IFG_RXIFG;
NVIC->ISER[0] &= ~(1 << ((EUSCIB0_IRQn) & 31));
}
//----------------------------------------------------------------------------------------
**Attention** This is a public forum