Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Arduino and MSP430 SPI

$
0
0

I am trying to get an Arduino Uno kit to communicate with an MSP4302012 using SPI, but I am having some difficulties. As far as I can tell by the debugging in CCS, I do not get nothing other than 0xFF in the USISRL register. The MISO and MOSI lines are pulled high with 10k resistors bacause they are also used for I2C. I cannot seem to wrap my head around which clock polairty settings etc. to choose. Any help would be mostly appreciated!

The Arduino will act as the master and transfer 1 byte per loop. Here's the master code

#include <SPI.h>

#define MOSI 11 // P1.6
#define MISO 12 // P1.7
#define SCLK 13 // P1.5
#define SS 10 // P1.2

void setup()
{
Serial.begin(9600);
SPI.setClockDivider(SPI_CLOCK_DIV128); //
pinMode(SCLK, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(SS, OUTPUT);

SPI.begin(); // wake up the SPI bus
SPI.setBitOrder(MSBFIRST); // Set order of read/write (Big endian)
SPI.setDataMode(SPI_MODE0); // Sample on rising, change on falling?
}

void loop()
{
digitalWrite(SS, LOW); // Select MSP430
delay(1); // Wait for MOSI to settle
SPI.transfer(0xAA); // Transfer 10101010
digitalWrite(SS, HIGH); // Deselect MSP30
delay(1000); // Delay for next cycle
}

The slave code for the MSP430 looks like this: 

#include <msp430.h>
char TxData;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR = BIT4; // P1.4 output
P1OUT &= ~BIT4;

// Slave by default
USICTL0 |= USIPE7 // Enable SPI input mode on P1.7
+ USIPE6 // Enable SPI output mode on P1.6
+ USIPE5 // MUX P1.5 to SCLK
+ USIOE; // Enable output
USICTL1 |= USIIE; // Counter interrupt, flag remains set
USICTL0 &= ~USISWRST; // USI released for operation
USISRL = 0x82; // init-load data
USICNT = 8; // init-load counter // init-load counter

_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}

// USI interrupt service routine
#pragma vector=USI_VECTOR
__interrupt void universal_serial_interface(void)
{
if (USISRL == 0x22)
{
P1OUT ^= BIT4;
TxData = USISRL;
}
USICNT = 8; // re-load counter
}

Edit: Pasted wrong code


Viewing all articles
Browse latest Browse all 262198

Trending Articles



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