Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

G2553 4 wire SPI Slave always seems enabled

$
0
0

The following code accepts over the SPI bus a byte from the master to control 8 relays, and returns the state of 8 inputs.

I am running into an issue where the slave always responds to the SCLK, driving MISO, even when the STE (pin 1.4) is not asserted low.

Any ideas why?

#include "msp430g2553.h"
#include <string.h>


enum {
	/* Port 1 */
	LED1 = BIT0
	,LED2 = BIT1
};

int main(void){
	WDTCTL = WDTPW | WDTHOLD;

	BCSCTL1 = CALBC1_16MHZ;
	DCOCTL = CALDCO_16MHZ;

	/* SMCLK = DCO / DIVS = nMHz */
	/* ACLK = VLO = ~ 12 KHz */
	BCSCTL2 &= ~(DIVS_0);
	BCSCTL3 |= LFXT1S_2; 

	P2SEL &= ~(BIT6 | BIT7);

	/* Enable SPI */
	P1SEL |= BIT4 | BIT5 | BIT6 | BIT7;
	P1SEL2 |= BIT4 | BIT5 | BIT6 | BIT7;
	UCB0CTL1 = UCSWRST;
	UCB0CTL0 = UCSYNC | UCMODE_2 | UCMSB | UCCKPH;
	UCB0BR0 = 0;
	UCB0BR1 = 0;
	UCB0CTL1 &= ~UCSWRST;

	IE2 |= UCB0RXIE | UCB0TXIE;

	P1DIR = LED1 | LED2;

	P2OUT = 0xFF;
	P2REN |= 0xFF;

	P1IFG = 0;
	P2IFG = 0;

	/* Default state is to output. */
	P3OUT = 0xFF;
	P3DIR = 0xFF;

	__eint();
	LPM0;
}


__attribute__((interrupt(USCIAB0RX_VECTOR)))
void USCI0RX_ISR(void)
{
	P1OUT ^= LED2;
	uint8_t relays = UCB0RXBUF;
	P3OUT = relays;
}

__attribute__((interrupt(USCIAB0TX_VECTOR)))
void USCI0TX_ISR(void)
{
	P1OUT ^= LED1;
	UCB0TXBUF = P2IN;
}

Viewing all articles
Browse latest Browse all 2077

Trending Articles