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

msp430g2553 SPI help

$
0
0

Hi All,

This is my first post here and I am unfamiliar with posting in forums, so go easy on me! ;)

I am trying to use an MSP430G255G (on a launchpad using CCSv5) to get SPI running. It is a 1 master 1 slave system (msp430 is master and EEPROM is slave). I have a few questions in general, and the question of why my code isn't working.

1. Firstly, above I mentioned that it is a 1 master system. I thought all SPI was until today. Can someone clarify for me that the STE function IS NOT the same as a chip select? I need to assign a GPIO for my chip select line, right?

2. I want to know exactly what "_enable_interrupts()" does. If you can point me to a document (I have looked) that would be great. Does it in-line assembly instructions to enable all interrupts and flags that the chip has?

3. My code doesn't work! I have structured it in various .c files and made - what I believe to be - good use of headers. The code compiles, and the UART functionality works fine, but I don't seem to be getting any data from my EEPROM. I will copy what I believe to be the relevant parts of my code.

OK, so a brief description of what I am trying to do first I think:

I wish to send 5 byte commands through the COM port to the MSP430 - this works, I am 99% sure of it as I get the expected replies.

These 5 bytes will be structured as {command number, address bits 23 to 16, address bits 15 to 8, address bits 7 to 0, data byte}. commands are instructions to the EEPROM, the address is the memory address of the EEPROM if required for the instruction, and the data byte is as you would expect.

The MSP has UCSI_A0 used for UART, and UCSI_B0 set up for SPI. It takes the command and calls the required SPI function, then gets the SPI reply and returns it via UART to my PC.

My SPI initialization function: 

void SPI_InitEEPROM(void)
{
    UCB0CTL1 |= UCSWRST;                    /* put UCSI_B0 into reset before operating on registers */
    /* SPI Pin Setup */
    P1OUT |= EEPROM_CS;                        /* Set EEPROM CS as high, then as output */
    P1DIR |= EEPROM_CS;
    P1SEL |= BIT5 + BIT6 + BIT7;            /* P1.5 CLK + P1.6 MISO + P1.7 MOSI */
    P1SEL2|= BIT4 + BIT5 + BIT6 + BIT7;

    /* SPI Control Registers */
    UCB0CTL0 |= UCMSB + UCMST + UCMODE_0 ;     /* MSB first, Master mode, 3-pin SPI */
    UCB0CTL1 |= UCSSEL_2;                     /* SMCLK */
    UCB0BR0 = 0x08;                            /* Bit Rate Control Register */
    UCB0BR1 = 0x00;                         /* Bit clock pre-scale setting */

    IE2 |= UCB0TXIE + UCB0RXIE;    /* enable UCB0 Rx and Tx interrupts */

    UCB0CTL1 &= ~UCSWRST;    /* release UCSI_B0 from reset - run */
}

Now for a typical SPI function to talk to the EEPROM:

uint8 SPI_ReadStatusRegister(void)
{
    uint8 reply;
    reply = NO_REPLY;

    P1OUT &= ~EEPROM_CS;        /* pull EEPROM Chip Select Low */
    UCB0TXBUF = RDSR;            /* load Read Status Register Instruction into UCSI_BO Tx buffer to be sent */
    while (!(IFG2 & UCB0TXIFG));/* wait for TX buffer ready */
    UCB0TXBUF = NULL;            /* Dummy byte to get Rx Data */
    while (!(IFG2 & UCB0TXIFG));/* wait for TX buffer ready */
    while (UCB0STAT & UCBUSY);     /* wait for the tx to complete */
    P1OUT |= EEPROM_CS;            /* release EEPROM CS */
    reply = UCB0RXBUF;            /* reply is most recent data received */

    return reply;
}

Hopefully one of you clever people will spot an error with this immediately :) Thanks for any help.

PS: UCSIB0CTL0 has Bit 0 for asynchronous.synchronous mode, isn't all SPI synchronous i.e. shares a clock?


Viewing all articles
Browse latest Browse all 262198

Trending Articles



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