Part Number: MSP-EXP432E401Y
Other Parts Discussed in Thread: MSP432E401Y
Stefan - First, wish to thank you for your earlier help on these SPI questions...
Am changing things up: Have now experimenting with 3-wire implementation - with the MSP432E401Y chatting with a 25LC1024. Code is based as closely as possible on the spimaster example, from simplelink_msp432e4_sdk_4_20_00_12 - with all the master-slave handshaking bits removed.
Port D lines are per defaults, with key pins now set up as discrete GPIO lines: (The syscfg tool has been very helpful here; thanks for this!)
EEPROM_CS - PD2
EEPROM_HOLD - PD5
EEPROM_WP - PD4
Tweaking various parameters, the first 2-3 bytes (of my all-important message "DON'T MESS WITH TEXAS") are always wrong. Assuming I have a timing issue, I've been trying to move around the CS and HOLD signals. Please note: the CS in trace below is at about 16µs before first byte sent - there is a 50 ns minimum CS setup time per DataSheet.
On a (perhaps?) related note: Have tried to use the usleep() function to tweak µs delays, but resultant delays are in the millisecond range. What do I need to know?
SPI_Params_init(&spiParams);
// SPI now in 3-wire mode? Will this help control over the CS?
Display_printf(display, 0, 0, " - setting up SPI_Params...\n");
spiParams.frameFormat = SPI_POL0_PHA1; // other code suggests Mode 3 - POL1 PH1
spiParams.bitRate = 10000000; // SLAVE MAX 10 MHZ ON MSP432E4 - so 25LC1024 can be 3.3v
spiParams.dataSize = 8; /* <-LOU MOD dataSize can range from 4 to 8 bits */
masterSpi = SPI_open(CONFIG_SPI_MASTER, &spiParams);
if (masterSpi == NULL) {
Display_printf(display, 0, 0, "Error initializing master SPI\n");
while (1);
}
else {
Display_printf(display, 0, 0, "Master SPI initialized\n");
}
/* Copy message to transmit buffer */
strncpy((char *) masterTxBuffer, MASTER_MSG, SPI_MSG_LENGTH);
for (i = 0; i < MAX_LOOP; i++) {
/* Datasheet: "The CS pin must be low and the HOLD pin must be high for the entire operation." */
///////////////////////////////////////////////////////////////////////////////
GPIO_write(EEPROM_CS, 0); // pulls low
GPIO_write(EEPROM_HOLD, 1); // pulls high
/* ----------------------------------------------
* Initialize master SPI transaction structure --- */
masterTxBuffer[sizeof(MASTER_MSG) - 1] = (i % 10) + '0'; // ORIGINAL
memset((void *) masterRxBuffer, 0, SPI_MSG_LENGTH);
transaction.count = SPI_MSG_LENGTH; // SPI_MSG_LENGTH;
// tDaughterComs.count = (sizeof(SpiRxBuffer) / sizeof(SpiRxBuffer[0]));
transaction.txBuf = (void *) masterTxBuffer;
transaction.rxBuf = (void *) masterRxBuffer;
/* Toggle user LED, indicating a SPI transfer is in progress */
GPIO_toggle(CONFIG_GPIO_LED_1);
// usleep(1); // 1µs ?? I hope? -- much too long (1 OR 10 µs generates 1.8+ ms delay until first result!)
/* Perform SPI transfer */
transferOK = SPI_transfer(masterSpi, &transaction);
if (transferOK) {
Display_printf(display, 0, 0, "Msg sent: %s", masterTxBuffer);
Display_printf(display, 0, 0, " -result: %s", masterRxBuffer);
}
else {
Display_printf(display, 0, 0, "Unsuccessful master SPI transfer");
}
/* Toggle user LED OFF */
GPIO_toggle(CONFIG_GPIO_LED_1);/* Sleep for a bit before starting the next SPI transfer */
sleep(2);
// --- DE-SELECT EEPROM
GPIO_write(EEPROM_HOLD, 0); // Pull HOLD LOW - end of operation
GPIO_write(EEPROM_CS, 1); // pulls high
}
SPI_close(masterSpi);
