I have been attemting to Coordinate my MSP430 with a seperate Flash chip known as the N25Q00AA. Over a month ago I posted a problem I was having on the forum as can be seen here for anyone that wishes to look back and see what was previously discussed.
Since then, I feel that progress has been made. However, a new problem has arisen since then, making the SPI functionality of my chip work properly. While using a Oscilloscope to determine what was outputting from my system, I noticed that the SPI outputs of my device were all showing only noise, and no visible pattern could be observed. This is clearly a problem, as the system should be outputting at least something from the SPI clock output.
To clarify, I wish to use my MSP430FR5728 in SPI B0 mode, and have the MSP be the master device with a separate flash memory chip being the slave device. I was not 100% sure how to select which clock source to use, so to be safe I had the ACLK, SMCLK, AND MCLK all operate at the same frequency of ~1MHz, which is well within the operating parameters of both of my devices. The MSP should also be outputting the command to the slave device, however I again am only seeing noise.
It is because of this that I believe that the problem is that I am not properly declaring what the pins functions should be. Within the MSP430FR57xx family user guide, page 295 details setting each pin for their function. I am sure that I selected the proper function setting for each SPI pin, but there is a possibility that I did not select the right state. The problem could lie elsewhere, and as such I will link my code below for everyone to see. If anyone could find the problem, I would greatly appreciate the help. Hope I used the insert code button correctly too
/*********************************************************** Code Goal: Write a Byte of data to address of N25Q00AA. After which, read the same address to prove that the data byte was properly recorded to the N25Q00AA. Write: Datasheet states need to Enable Write, send 3 address bytes, and requires the READ FLAG STATUS REGISTER command being issued with at least one byte output. Read: send 3 address bytes of where want to read Program: IAR Embedded Workbench IDE MCU: MSP430FR5728 SPI: B0 mode selected from device UCB0SIMO: P1.6 UCB0S0MI: P1.7 UCB0CLK: P2.2 CSn: PJ.1 ***********************************************************/ #include "string.h" #include "msp430.h" #include <stdio.h> char b1 = 0x03; // Flash Addr Part 1 for Write char b2 = 0xFF; // Flash Addr Part 2 for Write char b3 = 0xFF; // Flash Addr Part 3 for Write char b4 = 0x03; // Flash Addr Part 1 for Read char b5 = 0xFF; // Flash Addr Part 2 for Read char b6 = 0xFF; // Flash Addr Part 3 for Read char Q; unsigned char RXData =0; unsigned char TXData; /*************************************************** Flash Code ***************************************************/ char FlashByte(char S){ // General FlashByte Transmit while (!(UCB0IFG & UCTXIFG)); UCB0TXBUF = S; return (UCB0RXBUF); } char FlashComW(char x) // Write Command and Address { FlashByte(x); // Send Command and Address FlashByte(b1); FlashByte(b2); FlashByte(b3); Q = FlashByte(0xAA); // Send value to write return(Q); } char FlashComR(char x) // Read Command and Address { FlashByte(x); // Send Command and Address FlashByte(b4); FlashByte(b5); FlashByte(b6); Q = FlashByte(0xFF); // Send dummy value so read return(Q); } /*************************************************** Main Code ***************************************************/ int main(void){ WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer PJDIR |= 0x02; PJOUT |= 0x02; // Clock Setup For SPI CSCTL0_H = 0xA5; CSCTL1 |= DCOFSEL0 + DCOFSEL1; // Set DCO = 8MHz CSCTL2 = SELA_3 + SELS_3 + SELM_3; // set ACLK = SMCLK = MCLK = DCO CSCTL3 = DIVA_2 + DIVS_3 + DIVM_3; // ACLK -= SMCLK = MCLK = 1MHz // Configure SPI // Page 296 - Function Select Register P1SEL0 |= BIT6 + BIT7; // Set pins for primary purpose P2SEL0 |= BIT2; // Set pin for primary purpose UCB0CTLW0 = UCMST|UCSYNC|UCMSB|UCSSEL_1|UCSWRST; UCB0BR0 = 0x02; // /2 UCB0BR1 = 0; // UCB0CTLW0 &= ~UCSWRST; for(;;){ /****** Write ******/ // Write Enable Command PJOUT &= ~BIT1; FlashByte(0x06); PJOUT |= BIT1; // Write Command/Address PJOUT &= ~BIT1; FlashComW(0x02); PJOUT |= BIT1; // Write Disabled PJOUT &= ~BIT1; FlashByte(0x04); PJOUT |= BIT1; // Read Flag Status Register PJOUT &= ~BIT1; FlashByte(0x70); PJOUT |= BIT1; /****** Read ******/ // Read Command/Address PJOUT &= ~BIT1; printf("check = %X\r\n",FlashComR(0x03)); PJOUT |= BIT1; /****** Erase ******/ // Write Enable Command PJOUT &= ~BIT1; FlashByte(0x06); PJOUT |= BIT1; // Erase Command/Address PJOUT &= ~BIT1; FlashComW(0x20); PJOUT |= BIT1; // Write Disabled PJOUT &= ~BIT1; FlashByte(0x04); PJOUT |= BIT1; } }
It may also be worth noting two more things. First is that I lacked a launchpad to use for testing this particular chip, however I did use the method show on the following website found here and I did test it with simpler codes that did work using the same setup. The second thing to mention is that the program I am using is IAR embedded workbench.