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.

RM46 LaunchPad/SPI and 25LC256

Other Parts Discussed in Thread: HALCOGEN

I'm trying to connect a RM46 LaunchPad a memory Microchip 25LC256 SPI, I have trouble interpreting the functions of CCS (Microchip) with an equivalent function in CCSV6 + HalCogen

//--- driver code ---- 

#define EEPROM_SELECT PIN_B15 

#define EEPROM_ADDRESS long int 
#define EEPROM_SIZE    32768 

void init_ext_eeprom() 

output_high(EEPROM_SELECT);    
setup_spi(SPI_MASTER | SPI_XMIT_L_TO_H | SPI_CLK_DIV_4 ); 


//-------------------------------- 
int1 ext_eeprom_ready(void) 

int8 data; 

output_low(EEPROM_SELECT); 
spi_write(0x05); 
data = spi_read(0); 
output_high(EEPROM_SELECT); 
return(!bit_test(data, 0)); 


//-------------------------------- 
void write_ext_eeprom(EEPROM_ADDRESS address, BYTE data) 

while(!ext_eeprom_ready()); 

output_low(EEPROM_SELECT); 
spi_write(0x06); 
output_high(EEPROM_SELECT); 

output_low(EEPROM_SELECT); 
spi_write(0x02); 
spi_write(address >> 8); 
spi_write(address); 
spi_write(data); 
output_high(EEPROM_SELECT); 

//-------------------------------- 

BYTE read_ext_eeprom(EEPROM_ADDRESS address) 

int8 data; 

while(!ext_eeprom_ready()); 

output_low(EEPROM_SELECT); 
spi_write(0x03); 
spi_write(address >> 8); 
spi_write(address); 

data = spi_read(0); 
output_high(EEPROM_SELECT); 

return(data); 

which are the equivalent functions(HalCoGen):

spi_write(Byte)---->(Microchip)   in CCSV6+HalcoGen---->???? 

data = spi_read(0); ---->(Microchip)  in CCSV6+HalcoGen---->???? 

I found in "HalCoGen help", the following functions, but require many parameters.

uint32  spiTransmitData (spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 *srcbuff)
uint32  spiReceiveData (spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 *destbuff)

I need help setting these parameters!!!

  • Martin,


    I will suggest to have a look to the example available in HalCogen.

    Go to Help->Examples and select RM46x You will find a source file named:

    example_spi_Master_Slave.c
    In this example SPI1 is used has master.
    Our SPI module can be used in 4 pins mode (SIMO, SOMI, CLK and CS)
    The module/driver will handle CS automatically.

    uint16 25LC256Read_Status[] = { 0x05, 0x00};
    uint16 25LC256Read_Addr[] = { 0x03, 0x00,0x00};

    uint16 Result[]{0x00;0x00,0x00,0x00};

        spiDAT1_t dataconfig1_t;

        dataconfig1_t.CS_HOLD = TRUE;                                            // In multi data transfer (more than 1 data) the CS will stay active
                                                                                                                 // This is what you want to access your memory
        dataconfig1_t.WDEL    = TRUE;
        dataconfig1_t.DFSEL   = SPI_FMT_0;                                      // Use Format0. This is defined in halcogen in the MIBSPI/SPI Data Format tab
                                                                                                                 // In your case, you will have to provide the baudrate you want and change the Charlen to 8 bits.
                                                                                                                 // There is no need for parity, Clock Polarity and Phase should stay unchecked.
        dataconfig1_t.CSNR    = 0xFE;

        /* Initiate SPI1 Transmit and Receive through Polling Mode*/
        spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 2, 25LC256Read_Status, Result);

    // This will send 2 data (0x05,0x00) to the memory and will get 2 data back in Result. Result[0] is dummy, Result[1] is the status.

    This function call will address MIBSPI1 in SPI mode (spiREG1), using the Data format defined in dataconfig1_t as following:

    // To read from the memory the data at location ADDh,ADDl

      25LC256Read_Addr[1]= ADDh;
      25LC256Read_Addr[2]= ADDl;

        spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 3, 25LC256Read_Addr, Result);

    This is just an example, you can if you want using our Halcogen api re-create the microchip one.

  • thank you very much for your quick response, immediately implement the code with their tips, I hope to have good results.

    Greetings Martin
  • I started the project in CCS, but when I run the program, I found a loop.

    It is very strange, because:

    / * 25LC256 EEPROM Ready? * /
    spiTransmitAndReceiveData (spiREG3, & dataconfig1_t, 2, StatusRead25LC256, Result25LC256);

    It works perfectly the communication with 25LC256, but when run the following Instruction.

    AddrRead25LC256 [1] = 0x00; // Page 0 of EEPROM
    AddrRead25LC256 [2] = 0x0A; // Address 10 of EEPROM25LC256

    spiTransmitAndReceiveData (spiREG1, & dataconfig1_t, 3, AddrRead25LC256, Result25LC256);

    appear this infinite loop 

    attached my program, also add the part to write in EEPROM:

    0118.SPI_3.rar

    also attached photos of the connections between Hercules and the 25LC256

  • I answered my own question, will overcome the infinite loop records misspelled "spiREG3", here the revised program.

    3683.SPI_3.rar

    I happened to remove the memory 25LC256 the breadboard and ran the debug program and  the program runs smoothly without being connected to the memory, can not understand, why SPI responds without memory connected?

  • Martin.

    Good to see that you are moving forward.

    Let me remind you the basic of SPI.
    SPI is a shift register that shifts the data out to slave (MSB) and shifts the data in from slave (LSB) on each clock edge according to Polarity and Phase.
    The Master provides the clock and does not care if a slave is attached or not.

    In your case, when the memory is disconnected the SPISOMI is internally pulled up and the Master will sample 1 for all bits (0xff for a 16 bit transfer)

    One solution is to start your communication by reading the memory status register. Out of reset, the value should be a known value that your application code can check. If it is not the correct one than you can conclude that the memory is not attached.
    This kind of handshake has to be part of your application (if relevant)


    Please let me know if I've answered your question.

  • thank you very much for your prompt response, I hope you have enjoyed a good weekend.


    my friends also working on the creation of libraries and your problem upload in this page, he use a logic analyzer and there seems to be a compatibility issue between the 25LC256 and Hercules RM46. (pls check the pictures of the comments)

  • Martin,


    I check the specification for the 25LC256. Here is the timing requirement for Serial Input and Serial Output timing.

    As you can see the SI is capture on the rising edge of SPICLK

    In the SPI init (via Halcogen) try to change the Phase from 0 to 1 (check box checked) This will delay the SPICLK half a cycle, making SPISIMO stable before the rising edge of the clock.

    This should fix the problem.

    Please let me know if this option is working.

  • Martin,


    Have you tried to change the Phase on your project? Is it working now?

  • change phase, but fails to achieve any results.


    Use an oscilloscope to see if the hercules generates a signal, but just realized that Hercules does not generate any signal, the pins do not change their status, also try to use the PINMUX with pins of MIBSPI3, but I not got nothing.
    the initial states SPI3 are:

    CS 0 = 0
    SOMI = 0
    MISO = 0
    CLOCK = 1

    at the beginning and end of operating the project, not change state.

    but on the configuration of HALCoGen, should have other initial states.

    CS0 = 1
    SOMI = 1
    SIMO = 1
    CLCK = 1

    why no output is generated?

    Once again, thank you very much for taking your time and help me.

    greetings Martin Valencia