This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Serial Flash SST25VF016B SPI interfacing with TM4C1231h6pm

Other Parts Discussed in Thread: TM4C1231H6PM

HI,

I am trying to access the Serial flash using tm4c1231h6pm.



SSI0 -> SST25VF016B ( supports mode 0 and mode 3)
 

 SSI0CLK(PA2) -  clk
-SSI0Fss(PA3) -  CS
-SSI0Rx(PA4)  -  Tx
-SSI0Tx(PA5)  -   Rx


typedef unsigned char  uint8;                   // defined for unsigned 8-bits integer variable     
typedef signed   char  int8;                    // defined for signed 8-bits integer variable        
typedef unsigned short uint16;                  // defined for unsigned 16-bits integer variable     
typedef signed   short int16;                   // defined for signed 16-bits integer variable         
typedef unsigned long   uint32;                  // defined for unsigned 32-bits integer variable     
typedef signed   long   int32;                   // defined for signed 32-bits integer variable         

void spi configuration()

{

 

//
    // The SSI0 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);

    //
    // For this example SSI0 is used with PortA[5:2].  GPIO port A needs to be
    // enabled so these pins can be used.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Configure the pin muxing for SSI0 functions on port A2, A3, A4, and A5.
    // This step is not necessary if your part does not support pin muxing.
    //
    GPIOPinConfigure(GPIO_PA2_SSI0CLK);
    GPIOPinConfigure(GPIO_PA3_SSI0FSS);
    GPIOPinConfigure(GPIO_PA4_SSI0RX);
    GPIOPinConfigure(GPIO_PA5_SSI0TX);

    //
    // Configure the GPIO settings for the SSI pins.  This function also gives
    // control of these pins to the SSI hardware.  Consult the data sheet to
    // see which functions are allocated per pin.
    // The pins are assigned as follows:
    //      PA5 - SSI0Tx
    //      PA4 - SSI0Rx
    //      PA3 - SSI0Fss
    //      PA2 - SSI0CLK
    //
    GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 |
                   GPIO_PIN_2);

    //
    // Configure and enable the SSI0 port for SPI master mode.
    //
    SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
                       SSI_MODE_MASTER, 20000000, 8);

    //
    // Enable the SSI0 module.
    //
    SSIEnable(SSI0_BASE);

}

 void Send_Byte(uint8 data)   
    {   
       uint32 NullData;   
       SSIDataPut(SSI0_BASE, data);     
       SSIDataGet(SSI0_BASE, &NullData);       // dummy read  ( is required ??)                                           
    }  

  uint8 Get_Byte(void)   
    {   
       uint32 ReadData;   
       
       SSIDataPut(SSI0_BASE, 0xFF);        // dummy write ( is required to read ??)                              
       SSIDataGet(SSI0_BASE, &ReadData);   
       return (uint8)ReadData;   
       
    }

 
  uint8 RdID(uint32* RcvbufPt)   
    {   
        uint32 temp = 0;   
               
             
          
            GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0) ;    //Chip select low        
            Send_Byte(0x9F);                        // command to send to get the id
                       
            temp = (temp | Get_Byte()) << 8;
            temp = (temp | Get_Byte()) << 8;     
                    temp = (temp | Get_Byte());         // 0xBF2541   
                    GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,1) ;    //chip select high     
            *RcvbufPt = temp;   
            return 1;   
         
           
       
    }  
 

uint32  ChipID = 0;  
int main()
{
    //80mhz
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_10MHZ);

    spi_configuration();
    
     RdID(&ChipID);

}

i cant able to read back the id, i want to know any issue in the code, how to debug where is the issue. plz guide on this.

7115.spi_external_flash.c
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
SSI0 -> SST25VF016B ( supports mode 0 and mode3)
SSI0CLK(PA2) - clk
-SSI0Fss(PA3) - CS
-SSI0Rx(PA4) - Tx
-SSI0Tx(PA5) - Rx
typedef unsigned char uint8; // defined for unsigned 8-bits integer variable
typedef signed char int8; // defined for signed 8-bits integer variable
typedef unsigned short uint16; // defined for unsigned 16-bits integer variable
typedef signed short int16; // defined for signed 16-bits integer variable
typedef unsigned long uint32; // defined for unsigned 32-bits integer variable
typedef signed long int32; // defined for signed 32-bits integer variable
void spi configuration()
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hello Mahendran,

    The serial flash requires that the CS be held low for the duration of the entire transaction which would not be the case if the CS/FSS is being driven by SSI. You have to configure the FSS pin as a GPIO and in the application code, drive it low before calling RdID and then drive it high after the function is done.

    Regards

    Amit

  • hi amith,

    i am doing that here right

      GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0) ;    //Chip select low        
                Send_Byte(0x9F);                        // command to send to get the id
                           
                temp = (temp | Get_Byte()) << 8;
                temp = (temp | Get_Byte()) << 8;     
                        temp = (temp | Get_Byte());         // 0xBF2541   
                        GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,1) ;    //chip select high

  • Hello Mahendran,

    But the configuration done in the init function is for SSI FSS signal.

    GPIOPinConfigure(GPIO_PA3_SSI0FSS);

    This has to be replaced as

    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3);

    GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3);

    Similarly

    GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 |
                       GPIO_PIN_2);

    has to be replaced as

    GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_2);

    Also the GPIO Pin Write must be done as for writting a 1

    GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,1)

    replaced by

    GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3, GPIO_PIN_3)

    Regards

    Amit

  • Hi ,

    i have done the changes as per u told, still i cant able to read data.  what else have to check,

  • Hello Mahendran

    Please attach the full source code. This in on the LaunchPad for TM4C123?

    Regards

    Amit

  • hi amith,

    plz find the code attached and i am using tiva series (TM4C1231H6PM).

    6305.spi_external_flash_1.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    //TM4C1231H6PM
    SSI0 -> SST25VF016B ( supports mode 0 and mode 3)
    SSI0CLK(PA2) - clk
    -SSI0Fss(PA3) - CS
    -SSI0Rx(PA4) - Tx
    -SSI0Tx(PA5) - Rx
    typedef unsigned char uint8; // defined for unsigned 8-bits integer variable
    typedef signed char int8; // defined for signed 8-bits integer variable
    typedef unsigned short uint16; // defined for unsigned 16-bits integer variable
    typedef signed short int16; // defined for signed 16-bits integer variable
    typedef unsigned long uint32; // defined for unsigned 32-bits integer variable
    typedef signed long int32; // defined for signed 32-bits integer variable
    void spi configuration()
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hello mahendran,

    1. Are you using a 10MHz crystal? since the launchpad comes with a 16MHz crystal.

    2. You have set the SSI Baud Rate for 20MHz. I would suggest doing it at 1MHz first as SPI Flash are tough to communicate with especially when there is wiring involved. Also do check that the Setup and Hold time for the SPI Flash meets the TIVA Electrical Timings.

    3. Can you try to capture a scope plot of the transaction to see if the SPI Flash is getting the command and responding to it. Please make sure that FSS, CLK, TX and RX are all available/

    Regards

    Amit

  • Hi,

    My custom board tm4c1231h6pm is with 10mhx crystal.

    anyway i will check the point  2 and 3 . soon and let u know the result.

    thanks for your help



  • //
        // The SSI0 peripheral must be enabled for use.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);

        //
        // For this example SSI0 is used with PortA[5:2].  GPIO port A needs to be
        // enabled so these pins can be used.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

        //
        // Configure the pin muxing for SSI0 functions on port A2, A3, A4, and A5.
        // This step is not necessary if your part does not support pin muxing.
        //
        GPIOPinConfigure(GPIO_PA2_SSI0CLK);
        GPIOPinConfigure(GPIO_PA4_SSI0RX);
        GPIOPinConfigure(GPIO_PA5_SSI0TX);

        //
        // Configure the GPIO settings for the SSI pins.  This function also gives
        // control of these pins to the SSI hardware.  Consult the data sheet to
        // see which functions are allocated per pin.
        // The pins are assigned as follows:
        //      PA5 - SSI0Tx
        //      PA4 - SSI0Rx
        //      PA3 - SSI0Fss
        //      PA2 - SSI0CLK
        //
        GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4  |
                       GPIO_PIN_2);                   // as per ur suggestion given yesterday

        //
        // Configure and enable the SSI0 port for SPI master mode.
        //
        SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
                           SSI_MODE_MASTER, 20000000, 8);

        GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3); // as per ur suggestion given yesterday

        GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3); // as per ur suggestion given yesterday
        //
        // Enable the SSI0 module.
        //
        SSIEnable(SSI0_BASE);
     as per this SSI0 configuration,

    CS -> is high

    SCLK -> high ( pull up is done)

    SI -> 0.8v

    SO-> 0.v

    but while sending data, clk is not generating, CS -> low, how to proceed further, any suggestions

  • Hello Mahendran

    The configuration is fine. Can you send a scope shot of what happens?

    Also how are you sending the data, the function is not mentioned here?

    Regards

    Amit

  • currently i dont have scope shot


                GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0) ;    //Chip select low        
                  SSIDataPut(SSI0_BASE, 0x9F);

    GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,GPIO_PIN_3) ;    //chip select high    

    one more thing i observed i havent seen this data on data register.
     

  • Hello Mahendran

    Please do put the while(SSIBusy(SSI0_BASE)); after the SSIDataPut API call to ensure data is shifted out before the CS is deasserted

    What is the system frequency you are using? I see that you have requested 20MHz for the SSI Clock. For this to happen the System clock has to be 40MHz minimum or else the API will not work.

    Scope Plot is always useful...

    Regards

    Amit

  • i tried putting while(SSIBusy(SSIO_BASE); same result.

    my sram supports only 20mhz in this case i cant communicate with SRAM with SPI

    SRAM( 23lcv512) part no. what i have to do in this case/

  • Hello Mahendran,

    I asked the system frequency? I do not see in the code post the SysCtlClockSet API which configures the TM4C123 system clock.

    Regards

    Amit

  • ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                           SYSCTL_XTAL_10MHZ);

    this is my system clock configuration.

    i am generating 80mhz

  • Hello Mahendran,

    Please zip and send the CCS project so that I can check on my Launchpad?

    Typically it should work.

    Regards

    Amit

  • Hi.

    This is my clock configuration

    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                           SYSCTL_XTAL_10MHZ);

    this is my system clock configuration.

    i am generating 80mhz

  • hi amith,

    i am using keil, not ccs, i have already attached my code in this thread, but u want me send the workspace.

  • Hello Mahendran

    I do not have a 10MHz crystal so I moved the System Clock to Internal 16MHz which would be there on every part. With the change and the code attached, I do see everything working on a scope

    8737.SSI.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    #include <stdint.h>
    #include <stdbool.h>
    #include <math.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "inc/hw_uart.h"
    #include "inc/hw_ssi.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/uart.h"
    #include "driverlib/ssi.h"
    #include "driverlib/fpu.h"
    #include "driverlib/timer.h"
    #include "utils/cpu_usage.h"
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Regards

    Amit

  • hi amith,

    can u attach the scope shot if possible, any way thanks for the confirmation, want to know the status of each pin after configuration, 

  • Hello Mahendran

    Attached is the scope plot of FSS and CLK

    I am not sure what you mean by Status of Pin Configuration. Do you mean the Register configuration?

    Regards

    Amit

  • yes register configuration only.

  • Hello Mahendran

    Here you go...

    Regards

    Amit

  • hi amith,

    Through scope we have seen the clk and data sending out from the tm4c1231h6pm, but i am not getting any response from the external flash. Still that issue is continue.

  • Hello Mahendran,

    Can you check the CS/FSS Pin? A scope plot of the CS, CLK, TX and RX would be extremely useful.

    Also the basic of all questions, is the Flash getting VCC=3.3V?

    Regards

    Amit

  • using multimeter i checked the power supply VCC=3.3 v , i will upload the scope information soon

  • mahendhran s said:
    using multimeter i checked the power supply VCC=3.3 v

    That answer hasn't the precision to comfort Amit.  (or interested - trying to assist - others)

    You must make any and all such measurements, "at the remote device!"  (i.e. anything can happen between the power supply and the (likely) wire leads routed to your SPI accessory device)

    Are you sure that your IC is (itself) functional (still) and wired correctly?  (sometimes there are key pins which must be precisely set (high or low))

    All interconnects between your MCU and the remote device should be matched in length - and as short as possible.  Any/all noise sources should be removed during your SPI testing.  You should confirm signal integrity at the remote device - scope measures @ the MCU are not sufficient.

    Amit has advised that you reduce your SSI speed from the 20MHz (still I see).  Appears you've not done that.  20MHz across long, wire leads is not famed as being, "robust."  The fact that the device may reach 20MHz does not insist that you transact ONLY at that rate.  I'd bet you that is - in fact - a maximum rate.  Slowing the SSI clock can only assist your effort...

    And - I've seen the SSI Put - hopefully the SSI Get is present & proper.  (I've not read the code - simply alerting to that particular SSI "gotcha.")

    Your post has lingered beyond one month.  Basic troubleshooting is beyond the intent of such an MCU forum - Amit has provided substantial (personal) assistance - have you no one in your firm or school or club who may further assist?

  • hi,

    9f data is am sending and the clk is also generated but i am not getting data from it.

  • Hi,

    I had a quick loock at your code - and for me does not seems very well structured - the write to flash must be preceded by outputting WREN command (set WREN bit in status register and this shoud be one command, i.e, rise SSIFSS), followed by the new write opcode, followed by three address bytes and followed by at least one data byte. (I think you have not managed very well the address.. please check again). 

    After that you must issue the READ command, again opcode, three address bytes, and data byte(s). 

    I will look again later.

    Petrei

  • Hello All,

    On top of what Petrei duly noted (+ the CS is not there on the plot.)

    Regards

    Amit