EmbeddedRelated.com
Forums
Memfault Beyond the Launch

how SST25VF010 driver for MSP430 SPI

Started by Unknown October 22, 2010
I used MSP430F5XX's SPI Module,in master
I can make it works with SST25VF010 flash chip
but i used IO simulation SPI,it does work!!!

who can tell me why?



Beginning Microcontrollers with the MSP430

help!!
----- Original Message -----
From: ??
To: m...
Sent: Friday, October 22, 2010 10:54 PM
Subject: [msp430] how SST25VF010 driver for MSP430 SPI

I used MSP430F5XX's SPI Module,in master
I can make it works with SST25VF010 flash chip
but i used IO simulation SPI,it does work!!!

who can tell me why?





The language barrier here seems more complicated here than with my
own poor English...
I guess you wanted to say:
- You are using the SPI module in master mode and it does not work
with SST25VF010 serial FLASH memory.
- When you use software bit-bang SPI with the same memory it does
work.
.
Your post lacks of all necessary information so no one here can
actually give a usefull help.
The problem can be wrong register setup, bad software
implementation, wrong timing, hardware issues like wrong pin use..
etc.
The rule is: if something works in some way and stop when you change
something then you know you made some mistake.
.
-Augusto
On Sex 22/10/10 12:59 , "??" 3...@163.com sent:
help!!
----- Original Message -----
From: ??
To: m...
Sent: Friday, October 22, 2010 10:54 PM
Subject: [msp430] how SST25VF010 driver for MSP430 SPI
I used MSP430F5XX's SPI Module,in master
I can make it works with SST25VF010 flash chip
but i used IO simulation SPI,it does work!!!
who can tell me why?





Check the code, it works with the SST25VF032B under uCLinux with
software SPI, if you understand C, then it will be very easy to understand:

/*

FlashW25Q16V.h

*/

#include "ks32c50.h"

#ifndef __FLASHW25Q16V_H
#define __FLASHW25Q16V_H

#define CS ( 1 << 1) // P1 - Bit 1 define macro
#define CLK ( 1 << 9) // P9 - Bit 9 define macro
#define IO0 ( 1 << 10) // P10 - Bit 10 define macro
#define IO1 ( 1 << 11) // P11 - Bit 11 define macro

#define CS_INIT IOPMOD |= CS; IOPDATA |= CS
#define CS_ACTIVE IOPDATA &= ~CS
#define CS_PASSIVE IOPDATA |= CS

#define CLK_INIT IOPMOD |= CLK; IOPDATA |= CLK
#define CLK_LOW IOPDATA &= ~CLK
#define CLK_HIGH IOPDATA |= CLK

#define IO0_OUT IOPMOD |= IO0
#define IO0_LOW IOPDATA &= ~IO0
#define IO0_HIGH IOPDATA |= IO0
#define IO0_IN IOPMOD &= ~IO0
#define IO0_STATE ( IOPDATA & IO0)

#define IO1_OUT IOPMOD |= IO1
#define IO1_LOW IOPDATA &= ~IO1
#define IO1_HIGH IOPDATA |= IO1
#define IO1_IN IOPMOD &= ~IO1
#define IO1_STATE ( IOPDATA & IO1)

#endif /* __FLASHW25Q16V_H */

C file:

#include
#include
#include
#include "ks32c50.h"
#include "machineword.h"
#include "FlashW25Q16V.h"

#define YES 1
#define NO 0

// This structure defines entries into the command table;
typedef struct {
UBYTE command_byte; // OpCode;
UBYTE arg_required; // Indicates argument requirement;
DWORD var_length; // Indicates varialble length transfer;
BYTE *name; // Name of command
} COMMAND;

#define READ_STATUS_REG1 0
#define READ_STATUS_REG2 1
#define MAN_DEVICE_ID 2
#define FAST_READ 3
#define BLOCK_ERASE 4
#define WRITE_ENABLE 5
#define WRITE_DISABLE 6
#define CHIP_ERASE 7
#define PAGE_PROGRAM 8
#define WRITE_STATUS_REG 9
#define BYTE_PROGRAM 10
#define AAI_Word_Program 11
#define EBSY 12
#define DBSY 13
// Command table for W25VF032B.
COMMAND commandlist[] = {
{ 0x05, NO, 0x00000001,"READ_STATUS_REG1\0" }, //
{ 0x35, NO, 0x00000001,"READ_STATUS_REG2\0" }, //
{ 0x90,YES, 0x00000002,"MAN_DEVICE_ID\0" }, //
{ 0x0B,YES, 0x00200000,"FAST_READ\0" }, //
{ 0xD8,YES, 0x00000000,"BLOCK_ERASE\0" }, //
{ 0x06, NO, 0x00000000,"WRITE_ENABLE\0" }, //
{ 0x04, NO, 0x00000000,"WRITE_DISABLE\0" }, //
{ 0xC7, NO, 0x00000000,"CHIP_ERASE\0" }, //
{ 0x02,YES, 0x00000100,"PAGE_PROGRAM\0" }, //
{ 0x01, NO, 0x00000002,"WRITE_STATUS_REG\0" }, //
{ 0x02,YES, 0x00000001,"BYTE_PROGRAM\0" }, //
{ 0xAD,YES, 0x00001000,"AAI_Word_Program\0" }, //
{ 0x70, NO, 0x00000000,"EBSY\0" }, //
{ 0x80, NO, 0x00000000,"DBSY\0" } //
};

void InitSystem( void){

CS_INIT;
CLK_INIT;
IO0_OUT;
IO1_IN;
}

DWORD SPI_8bits_SIGNLEOUT( BYTE DATA){

BYTE BITCOUNT;

IO0_OUT;
for( BITCOUNT=0; BITCOUNT<8; BITCOUNT++){
CLK_LOW;
if( (0x80 & DATA) != 0){
IO0_HIGH;
}else{
IO0_LOW;
}
DATA <<= 1;
CLK_HIGH;
}
}

BYTE SPI_8bits_SINGLEIN( void){

BYTE BITCOUNT;
BYTE RESULT = 0;

IO1_IN;
for( BITCOUNT=0; BITCOUNT<8; BITCOUNT++){
RESULT <<= 1;
CLK_LOW;
CLK_HIGH;
if( IO1_STATE){
RESULT |= 0x01;
}
}

return RESULT;
}

DWORD FLASHW25VF032B_Command_execute( UBYTE cmd, UDWORD argument, UBYTE
*pchar){

COMMAND request_command; // Local space for the command
table entry;
DWORD BYTECOUNTER;

request_command = commandlist[cmd];

CS_ACTIVE;
SPI_8bits_SIGNLEOUT( request_command.command_byte);
if( request_command.arg_required == YES){
SPI_8bits_SIGNLEOUT( ( UBYTE)((argument>>16) & 0xFF));
SPI_8bits_SIGNLEOUT( ( UBYTE)((argument>> 8) & 0xFF));
SPI_8bits_SIGNLEOUT( ( UBYTE)((argument>> 0) & 0xFF));
}

switch( cmd){
case FAST_READ:
SPI_8bits_SINGLEIN();
for(
BYTECOUNTER=0;BYTECOUNTER *( pchar + BYTECOUNTER) = SPI_8bits_SINGLEIN();
}
break;

case PAGE_PROGRAM:
for(
BYTECOUNTER=0;BYTECOUNTER SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER));
}
break;

case WRITE_STATUS_REG:
for(
BYTECOUNTER=0;BYTECOUNTER SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER));
}
break;

case BYTE_PROGRAM:
for(
BYTECOUNTER=0;BYTECOUNTER SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER));
}
break;

case AAI_Word_Program:
CS_ACTIVE;
BYTECOUNTER=0;
SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
CS_PASSIVE;
CS_ACTIVE;
while( IO1_STATE == 0);
CS_PASSIVE;
for(;BYTECOUNTER CS_ACTIVE;
SPI_8bits_SIGNLEOUT( request_command.command_byte);
SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
CS_PASSIVE;
CS_ACTIVE;
while( IO1_STATE == 0);
CS_PASSIVE;
}
break;

default:
for(
BYTECOUNTER=0;BYTECOUNTER *( pchar + BYTECOUNTER) = SPI_8bits_SINGLEIN();
}
break;
}
CS_PASSIVE;

return request_command.var_length;
}

DWORD main(DWORD argc, BYTE *argv[]){

DWORD BYTECOUNTER, RESULT, i, j, FILE_LENTGH, START_ADDRESS;
BYTE *inBUFFER, DUMMY;
FILE *lst;

InitSystem();

inBUFFER = (char *)malloc( 0x200000);
if( inBUFFER == NULL){
printf( "\n No free memory! \n");
return 0;
}

switch( argc){
case 2:
if( strcmp( argv[1],"-e") == 0){

//***********************************************************************//

// //

//***********************************************************************//
printf( "Chip erase execute:\n");
FLASHW25VF032B_Command_execute( WRITE_ENABLE, 0, NULL );
FLASHW25VF032B_Command_execute( CHIP_ERASE, 0, NULL );
do{
FLASHW25VF032B_Command_execute( READ_STATUS_REG1,
0, &DUMMY);
printf( "-");
}while( (DUMMY & 0x01) == 1);
printf( "\n");
FLASHW25VF032B_Command_execute( WRITE_DISABLE, 0, NULL );

}else if( strcmp( argv[1],"-st") == 0){

//***********************************************************************//

// //

//***********************************************************************//
RESULT = FLASHW25VF032B_Command_execute(
READ_STATUS_REG1, 0, inBUFFER );
printf( " REG1: ");
for( BYTECOUNTER=0;BYTECOUNTER printf( " %02X", *( inBUFFER + BYTECOUNTER));
}
printf( "\n");

RESULT = FLASHW25VF032B_Command_execute(
READ_STATUS_REG2, 0, inBUFFER );
printf( " REG2: ");
for( BYTECOUNTER=0;BYTECOUNTER printf( " %02X", *( inBUFFER + BYTECOUNTER));
}
printf( "\n");

}else if( strcmp( argv[1],"-id") == 0){

//***********************************************************************//

// //

//***********************************************************************//
RESULT = FLASHW25VF032B_Command_execute( MAN_DEVICE_ID,
0, inBUFFER );
printf( " JEDEC: ");
for( BYTECOUNTER=0;BYTECOUNTER printf( " %02X", *( inBUFFER + BYTECOUNTER));
}
printf( "\n");

}else if( strcmp( argv[1],"-ee") == 0){

//***********************************************************************//

// //

//***********************************************************************//
FLASHW25VF032B_Command_execute( WRITE_ENABLE, 0, NULL );

*(inBUFFER + 0) = 0x00;
*(inBUFFER + 1) = 0x00;

FLASHW25VF032B_Command_execute( WRITE_STATUS_REG, 0,
inBUFFER );
FLASHW25VF032B_Command_execute( WRITE_DISABLE, 0,NULL );

}else{

//***********************************************************************//

// //

//***********************************************************************//
printf( "Wrong option: %s\n", argv[1]);
}
break;

case 4:
if( strcmp( argv[1],"-r") == 0){

//***********************************************************************//

// //

//***********************************************************************//
START_ADDRESS = atoi(argv[2]);
RESULT = FLASHW25VF032B_Command_execute( FAST_READ,
START_ADDRESS, inBUFFER );
lst = fopen( argv[3], "w+");
if( lst == NULL){
printf( "File creation error: %s\n", argv[3]);
}else{
for( BYTECOUNTER=0;BYTECOUNTER fputc( *( inBUFFER + BYTECOUNTER), lst);
}
fclose( lst);
}

/*
for( i=0; i printf(" 0x%04X :", i << 4);
for( j=0; j<16; j++){
printf(" %02X", *( inBUFFER + i*16 + j));
}
printf("\n");
}*/
}else if( strcmp( argv[1],"-pr") == 0){

//***********************************************************************//

// //

//***********************************************************************//
lst = fopen( argv[3], "r+");
if( lst == NULL){
printf( "File read error: %s\n", argv[3]);
}else{
FILE_LENTGH = 0;
while (!feof( lst)){
*( inBUFFER + FILE_LENTGH) = fgetc( lst);
FILE_LENTGH++;
if( (FILE_LENTGH-1) > 0x200000){
fclose( lst);
printf( "Opened file is more then
0x200000!\n");
break;
}
}
fclose( lst);
FILE_LENTGH -= 1;
printf( "File length 0x%08X\n", FILE_LENTGH);
FILE_LENTGH &= 0xFFFFF000;
START_ADDRESS = atoi(argv[2]);
for( i=0; i < FILE_LENTGH; i+=0x1000){
printf( "ADDRESS 0x%08X\n", i + START_ADDRESS);
FLASHW25VF032B_Command_execute( WRITE_ENABLE,
0,NULL );
FLASHW25VF032B_Command_execute( EBSY, 0,NULL );
FLASHW25VF032B_Command_execute(
AAI_Word_Program, (DWORD)i + START_ADDRESS, (inBUFFER + i));
FLASHW25VF032B_Command_execute( WRITE_DISABLE,
0, NULL );
FLASHW25VF032B_Command_execute( DBSY, 0,NULL );
}
printf( "\n");
}
}else{

//***********************************************************************//

// //

//***********************************************************************//
printf( "Wrong option: %s\n", argv[1]);
}
break;
default:
printf( "Need more arguments!\n");
break;
}
free( inBUFFER);
return 0;
}

With my best regards,

Alex

On 10/22/2010 10:59, ?? wrote:
>
> help!!
> ----- Original Message -----
> From: ??
> To: m...
> Sent: Friday, October 22, 2010 10:54 PM
> Subject: [msp430] how SST25VF010 driver for MSP430 SPI
>
> I used MSP430F5XX's SPI Module,in master
> I can make it works with SST25VF010 flash chip
> but i used IO simulation SPI,it does work!!!
>
> who can tell me why?
>
>
>
>


Thank you a lot!!!
what my situation now was:
Software SPI that I wrote is work well now.
but I try to do this with using the SPI module in master mode,and it does't work well
I found that it just can read data out from SST25VF010,but i can't write data to it.
thank you for your helping, I check the Code again

----- Original Message -----
From: Alexandar Kalaydjiev
To: m...
Sent: Saturday, October 23, 2010 12:11 AM
Subject: Re: [msp430] how SST25VF010 driver for MSP430 SPI

Check the code, it works with the SST25VF032B under uCLinux with
software SPI, if you understand C, then it will be very easy to understand:

/*

FlashW25Q16V.h

*/

#include "ks32c50.h"

#ifndef __FLASHW25Q16V_H
#define __FLASHW25Q16V_H

#define CS ( 1 << 1) // P1 - Bit 1 define macro
#define CLK ( 1 << 9) // P9 - Bit 9 define macro
#define IO0 ( 1 << 10) // P10 - Bit 10 define macro
#define IO1 ( 1 << 11) // P11 - Bit 11 define macro

#define CS_INIT IOPMOD |= CS; IOPDATA |= CS
#define CS_ACTIVE IOPDATA &= ~CS
#define CS_PASSIVE IOPDATA |= CS

#define CLK_INIT IOPMOD |= CLK; IOPDATA |= CLK
#define CLK_LOW IOPDATA &= ~CLK
#define CLK_HIGH IOPDATA |= CLK

#define IO0_OUT IOPMOD |= IO0
#define IO0_LOW IOPDATA &= ~IO0
#define IO0_HIGH IOPDATA |= IO0
#define IO0_IN IOPMOD &= ~IO0
#define IO0_STATE ( IOPDATA & IO0)

#define IO1_OUT IOPMOD |= IO1
#define IO1_LOW IOPDATA &= ~IO1
#define IO1_HIGH IOPDATA |= IO1
#define IO1_IN IOPMOD &= ~IO1
#define IO1_STATE ( IOPDATA & IO1)

#endif /* __FLASHW25Q16V_H */

C file:

#include
#include
#include
#include "ks32c50.h"
#include "machineword.h"
#include "FlashW25Q16V.h"

#define YES 1
#define NO 0

// This structure defines entries into the command table;
typedef struct {
UBYTE command_byte; // OpCode;
UBYTE arg_required; // Indicates argument requirement;
DWORD var_length; // Indicates varialble length transfer;
BYTE *name; // Name of command
} COMMAND;

#define READ_STATUS_REG1 0
#define READ_STATUS_REG2 1
#define MAN_DEVICE_ID 2
#define FAST_READ 3
#define BLOCK_ERASE 4
#define WRITE_ENABLE 5
#define WRITE_DISABLE 6
#define CHIP_ERASE 7
#define PAGE_PROGRAM 8
#define WRITE_STATUS_REG 9
#define BYTE_PROGRAM 10
#define AAI_Word_Program 11
#define EBSY 12
#define DBSY 13

// Command table for W25VF032B.
COMMAND commandlist[] = {
{ 0x05, NO, 0x00000001,"READ_STATUS_REG1\0" }, //
{ 0x35, NO, 0x00000001,"READ_STATUS_REG2\0" }, //
{ 0x90,YES, 0x00000002,"MAN_DEVICE_ID\0" }, //
{ 0x0B,YES, 0x00200000,"FAST_READ\0" }, //
{ 0xD8,YES, 0x00000000,"BLOCK_ERASE\0" }, //
{ 0x06, NO, 0x00000000,"WRITE_ENABLE\0" }, //
{ 0x04, NO, 0x00000000,"WRITE_DISABLE\0" }, //
{ 0xC7, NO, 0x00000000,"CHIP_ERASE\0" }, //
{ 0x02,YES, 0x00000100,"PAGE_PROGRAM\0" }, //
{ 0x01, NO, 0x00000002,"WRITE_STATUS_REG\0" }, //
{ 0x02,YES, 0x00000001,"BYTE_PROGRAM\0" }, //
{ 0xAD,YES, 0x00001000,"AAI_Word_Program\0" }, //
{ 0x70, NO, 0x00000000,"EBSY\0" }, //
{ 0x80, NO, 0x00000000,"DBSY\0" } //
};

void InitSystem( void){

CS_INIT;
CLK_INIT;
IO0_OUT;
IO1_IN;
}

DWORD SPI_8bits_SIGNLEOUT( BYTE DATA){

BYTE BITCOUNT;

IO0_OUT;
for( BITCOUNT=0; BITCOUNT<8; BITCOUNT++){
CLK_LOW;
if( (0x80 & DATA) != 0){
IO0_HIGH;
}else{
IO0_LOW;
}
DATA <<= 1;
CLK_HIGH;
}
}

BYTE SPI_8bits_SINGLEIN( void){

BYTE BITCOUNT;
BYTE RESULT = 0;

IO1_IN;
for( BITCOUNT=0; BITCOUNT<8; BITCOUNT++){
RESULT <<= 1;
CLK_LOW;
CLK_HIGH;
if( IO1_STATE){
RESULT |= 0x01;
}
}

return RESULT;
}

DWORD FLASHW25VF032B_Command_execute( UBYTE cmd, UDWORD argument, UBYTE
*pchar){

COMMAND request_command; // Local space for the command
table entry;
DWORD BYTECOUNTER;

request_command = commandlist[cmd];

CS_ACTIVE;
SPI_8bits_SIGNLEOUT( request_command.command_byte);
if( request_command.arg_required == YES){
SPI_8bits_SIGNLEOUT( ( UBYTE)((argument>>16) & 0xFF));
SPI_8bits_SIGNLEOUT( ( UBYTE)((argument>> 8) & 0xFF));
SPI_8bits_SIGNLEOUT( ( UBYTE)((argument>> 0) & 0xFF));
}

switch( cmd){
case FAST_READ:
SPI_8bits_SINGLEIN();
for(
BYTECOUNTER=0;BYTECOUNTER *( pchar + BYTECOUNTER) = SPI_8bits_SINGLEIN();
}
break;

case PAGE_PROGRAM:
for(
BYTECOUNTER=0;BYTECOUNTER SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER));
}
break;

case WRITE_STATUS_REG:
for(
BYTECOUNTER=0;BYTECOUNTER SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER));
}
break;

case BYTE_PROGRAM:
for(
BYTECOUNTER=0;BYTECOUNTER SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER));
}
break;

case AAI_Word_Program:
CS_ACTIVE;
BYTECOUNTER=0;
SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
CS_PASSIVE;
CS_ACTIVE;
while( IO1_STATE == 0);
CS_PASSIVE;
for(;BYTECOUNTER CS_ACTIVE;
SPI_8bits_SIGNLEOUT( request_command.command_byte);
SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
CS_PASSIVE;
CS_ACTIVE;
while( IO1_STATE == 0);
CS_PASSIVE;
}
break;

default:
for(
BYTECOUNTER=0;BYTECOUNTER *( pchar + BYTECOUNTER) = SPI_8bits_SINGLEIN();
}
break;
}
CS_PASSIVE;

return request_command.var_length;
}

DWORD main(DWORD argc, BYTE *argv[]){

DWORD BYTECOUNTER, RESULT, i, j, FILE_LENTGH, START_ADDRESS;
BYTE *inBUFFER, DUMMY;
FILE *lst;

InitSystem();

inBUFFER = (char *)malloc( 0x200000);
if( inBUFFER == NULL){
printf( "\n No free memory! \n");
return 0;
}

switch( argc){
case 2:
if( strcmp( argv[1],"-e") == 0){

//***********************************************************************//

// //

//***********************************************************************//
printf( "Chip erase execute:\n");
FLASHW25VF032B_Command_execute( WRITE_ENABLE, 0, NULL );
FLASHW25VF032B_Command_execute( CHIP_ERASE, 0, NULL );
do{
FLASHW25VF032B_Command_execute( READ_STATUS_REG1,
0, &DUMMY);
printf( "-");
}while( (DUMMY & 0x01) == 1);
printf( "\n");
FLASHW25VF032B_Command_execute( WRITE_DISABLE, 0, NULL );

}else if( strcmp( argv[1],"-st") == 0){

//***********************************************************************//

// //

//***********************************************************************//
RESULT = FLASHW25VF032B_Command_execute(
READ_STATUS_REG1, 0, inBUFFER );
printf( " REG1: ");
for( BYTECOUNTER=0;BYTECOUNTER printf( " %02X", *( inBUFFER + BYTECOUNTER));
}
printf( "\n");

RESULT = FLASHW25VF032B_Command_execute(
READ_STATUS_REG2, 0, inBUFFER );
printf( " REG2: ");
for( BYTECOUNTER=0;BYTECOUNTER printf( " %02X", *( inBUFFER + BYTECOUNTER));
}
printf( "\n");

}else if( strcmp( argv[1],"-id") == 0){

//***********************************************************************//

// //

//***********************************************************************//
RESULT = FLASHW25VF032B_Command_execute( MAN_DEVICE_ID,
0, inBUFFER );
printf( " JEDEC: ");
for( BYTECOUNTER=0;BYTECOUNTER printf( " %02X", *( inBUFFER + BYTECOUNTER));
}
printf( "\n");

}else if( strcmp( argv[1],"-ee") == 0){

//***********************************************************************//

// //

//***********************************************************************//
FLASHW25VF032B_Command_execute( WRITE_ENABLE, 0, NULL );

*(inBUFFER + 0) = 0x00;
*(inBUFFER + 1) = 0x00;

FLASHW25VF032B_Command_execute( WRITE_STATUS_REG, 0,
inBUFFER );
FLASHW25VF032B_Command_execute( WRITE_DISABLE, 0,NULL );

}else{

//***********************************************************************//

// //

//***********************************************************************//
printf( "Wrong option: %s\n", argv[1]);
}
break;

case 4:
if( strcmp( argv[1],"-r") == 0){

//***********************************************************************//

// //

//***********************************************************************//
START_ADDRESS = atoi(argv[2]);
RESULT = FLASHW25VF032B_Command_execute( FAST_READ,
START_ADDRESS, inBUFFER );
lst = fopen( argv[3], "w+");
if( lst == NULL){
printf( "File creation error: %s\n", argv[3]);
}else{
for( BYTECOUNTER=0;BYTECOUNTER fputc( *( inBUFFER + BYTECOUNTER), lst);
}
fclose( lst);
}

/*
for( i=0; i printf(" 0x%04X :", i << 4);
for( j=0; j<16; j++){
printf(" %02X", *( inBUFFER + i*16 + j));
}
printf("\n");
}*/
}else if( strcmp( argv[1],"-pr") == 0){

//***********************************************************************//

// //

//***********************************************************************//
lst = fopen( argv[3], "r+");
if( lst == NULL){
printf( "File read error: %s\n", argv[3]);
}else{
FILE_LENTGH = 0;
while (!feof( lst)){
*( inBUFFER + FILE_LENTGH) = fgetc( lst);
FILE_LENTGH++;
if( (FILE_LENTGH-1) > 0x200000){
fclose( lst);
printf( "Opened file is more then
0x200000!\n");
break;
}
}
fclose( lst);
FILE_LENTGH -= 1;
printf( "File length 0x%08X\n", FILE_LENTGH);
FILE_LENTGH &= 0xFFFFF000;
START_ADDRESS = atoi(argv[2]);
for( i=0; i < FILE_LENTGH; i+=0x1000){
printf( "ADDRESS 0x%08X\n", i + START_ADDRESS);
FLASHW25VF032B_Command_execute( WRITE_ENABLE,
0,NULL );
FLASHW25VF032B_Command_execute( EBSY, 0,NULL );
FLASHW25VF032B_Command_execute(
AAI_Word_Program, (DWORD)i + START_ADDRESS, (inBUFFER + i));
FLASHW25VF032B_Command_execute( WRITE_DISABLE,
0, NULL );
FLASHW25VF032B_Command_execute( DBSY, 0,NULL );
}
printf( "\n");
}
}else{

//***********************************************************************//

// //

//***********************************************************************//
printf( "Wrong option: %s\n", argv[1]);
}
break;
default:
printf( "Need more arguments!\n");
break;
}
free( inBUFFER);
return 0;
}

With my best regards,

Alex

On 10/22/2010 10:59, ?? wrote:
>
> help!!
>
>
> ----- Original Message -----
> From: ??
> To: m...
> Sent: Friday, October 22, 2010 10:54 PM
> Subject: [msp430] how SST25VF010 driver for MSP430 SPI
>
>
>
> I used MSP430F5XX's SPI Module,in master
> I can make it works with SST25VF010 flash chip
> but i used IO simulation SPI,it does work!!!
>
> who can tell me why?
>
>
>
>
>
>
>
>
>
>





Post your code, there are too many place for errors, it will be easier.

With my best regards,

Alex
On 10/23/2010 05:12, 六月 wrote:
>
> Thank you a lot!!!
> what my situation now was:
> Software SPI that I wrote is work well now.
> but I try to do this with using the SPI module in master mode,and it
> does't work well
> I found that it just can read data out from SST25VF010,but i can't
> write data to it.
> thank you for your helping, I check the Code again
>
> ----- Original Message -----
> From: Alexandar Kalaydjiev
> To: m...
> Sent: Saturday, October 23, 2010 12:11 AM
> Subject: Re: [msp430] how SST25VF010 driver for MSP430 SPI
>
> Check the code, it works with the SST25VF032B under uCLinux with
> software SPI, if you understand C, then it will be very easy to
> understand:
>
> /*
>
> FlashW25Q16V.h
>
> */
>
> #include "ks32c50.h"
>
> #ifndef __FLASHW25Q16V_H
> #define __FLASHW25Q16V_H
>
> #define CS ( 1 << 1) // P1 - Bit 1 define macro
> #define CLK ( 1 << 9) // P9 - Bit 9 define macro
> #define IO0 ( 1 << 10) // P10 - Bit 10 define macro
> #define IO1 ( 1 << 11) // P11 - Bit 11 define macro
>
> #define CS_INIT IOPMOD |= CS; IOPDATA |= CS
> #define CS_ACTIVE IOPDATA &= ~CS
> #define CS_PASSIVE IOPDATA |= CS
>
> #define CLK_INIT IOPMOD |= CLK; IOPDATA |= CLK
> #define CLK_LOW IOPDATA &= ~CLK
> #define CLK_HIGH IOPDATA |= CLK
>
> #define IO0_OUT IOPMOD |= IO0
> #define IO0_LOW IOPDATA &= ~IO0
> #define IO0_HIGH IOPDATA |= IO0
> #define IO0_IN IOPMOD &= ~IO0
> #define IO0_STATE ( IOPDATA & IO0)
>
> #define IO1_OUT IOPMOD |= IO1
> #define IO1_LOW IOPDATA &= ~IO1
> #define IO1_HIGH IOPDATA |= IO1
> #define IO1_IN IOPMOD &= ~IO1
> #define IO1_STATE ( IOPDATA & IO1)
>
> #endif /* __FLASHW25Q16V_H */
>
> C file:
>
> #include
> #include
> #include
> #include "ks32c50.h"
> #include "machineword.h"
> #include "FlashW25Q16V.h"
>
> #define YES 1
> #define NO 0
>
> // This structure defines entries into the command table;
> typedef struct {
> UBYTE command_byte; // OpCode;
> UBYTE arg_required; // Indicates argument requirement;
> DWORD var_length; // Indicates varialble length transfer;
> BYTE *name; // Name of command
> } COMMAND;
>
> #define READ_STATUS_REG1 0
> #define READ_STATUS_REG2 1
> #define MAN_DEVICE_ID 2
> #define FAST_READ 3
> #define BLOCK_ERASE 4
> #define WRITE_ENABLE 5
> #define WRITE_DISABLE 6
> #define CHIP_ERASE 7
> #define PAGE_PROGRAM 8
> #define WRITE_STATUS_REG 9
> #define BYTE_PROGRAM 10
> #define AAI_Word_Program 11
> #define EBSY 12
> #define DBSY 13
>
> // Command table for W25VF032B.
> COMMAND commandlist[] = {
> { 0x05, NO, 0x00000001,"READ_STATUS_REG1\0" }, //
> { 0x35, NO, 0x00000001,"READ_STATUS_REG2\0" }, //
> { 0x90,YES, 0x00000002,"MAN_DEVICE_ID\0" }, //
> { 0x0B,YES, 0x00200000,"FAST_READ\0" }, //
> { 0xD8,YES, 0x00000000,"BLOCK_ERASE\0" }, //
> { 0x06, NO, 0x00000000,"WRITE_ENABLE\0" }, //
> { 0x04, NO, 0x00000000,"WRITE_DISABLE\0" }, //
> { 0xC7, NO, 0x00000000,"CHIP_ERASE\0" }, //
> { 0x02,YES, 0x00000100,"PAGE_PROGRAM\0" }, //
> { 0x01, NO, 0x00000002,"WRITE_STATUS_REG\0" }, //
> { 0x02,YES, 0x00000001,"BYTE_PROGRAM\0" }, //
> { 0xAD,YES, 0x00001000,"AAI_Word_Program\0" }, //
> { 0x70, NO, 0x00000000,"EBSY\0" }, //
> { 0x80, NO, 0x00000000,"DBSY\0" } //
> };
>
> void InitSystem( void){
>
> CS_INIT;
> CLK_INIT;
> IO0_OUT;
> IO1_IN;
> }
>
> DWORD SPI_8bits_SIGNLEOUT( BYTE DATA){
>
> BYTE BITCOUNT;
>
> IO0_OUT;
> for( BITCOUNT=0; BITCOUNT<8; BITCOUNT++){
> CLK_LOW;
> if( (0x80 & DATA) != 0){
> IO0_HIGH;
> }else{
> IO0_LOW;
> }
> DATA <<= 1;
> CLK_HIGH;
> }
> }
>
> BYTE SPI_8bits_SINGLEIN( void){
>
> BYTE BITCOUNT;
> BYTE RESULT = 0;
>
> IO1_IN;
> for( BITCOUNT=0; BITCOUNT<8; BITCOUNT++){
> RESULT <<= 1;
> CLK_LOW;
> CLK_HIGH;
> if( IO1_STATE){
> RESULT |= 0x01;
> }
> }
>
> return RESULT;
> }
>
> DWORD FLASHW25VF032B_Command_execute( UBYTE cmd, UDWORD argument, UBYTE
> *pchar){
>
> COMMAND request_command; // Local space for the command
> table entry;
> DWORD BYTECOUNTER;
>
> request_command = commandlist[cmd];
>
> CS_ACTIVE;
> SPI_8bits_SIGNLEOUT( request_command.command_byte);
> if( request_command.arg_required == YES){
> SPI_8bits_SIGNLEOUT( ( UBYTE)((argument>>16) & 0xFF));
> SPI_8bits_SIGNLEOUT( ( UBYTE)((argument>> 8) & 0xFF));
> SPI_8bits_SIGNLEOUT( ( UBYTE)((argument>> 0) & 0xFF));
> }
>
> switch( cmd){
> case FAST_READ:
> SPI_8bits_SINGLEIN();
> for(
> BYTECOUNTER=0;BYTECOUNTER > *( pchar + BYTECOUNTER) = SPI_8bits_SINGLEIN();
> }
> break;
>
> case PAGE_PROGRAM:
> for(
> BYTECOUNTER=0;BYTECOUNTER > SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER));
> }
> break;
>
> case WRITE_STATUS_REG:
> for(
> BYTECOUNTER=0;BYTECOUNTER > SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER));
> }
> break;
>
> case BYTE_PROGRAM:
> for(
> BYTECOUNTER=0;BYTECOUNTER > SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER));
> }
> break;
>
> case AAI_Word_Program:
> CS_ACTIVE;
> BYTECOUNTER=0;
> SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
> SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
> CS_PASSIVE;
> CS_ACTIVE;
> while( IO1_STATE == 0);
> CS_PASSIVE;
> for(;BYTECOUNTER > CS_ACTIVE;
> SPI_8bits_SIGNLEOUT( request_command.command_byte);
> SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
> SPI_8bits_SIGNLEOUT( *( pchar + BYTECOUNTER++));
> CS_PASSIVE;
> CS_ACTIVE;
> while( IO1_STATE == 0);
> CS_PASSIVE;
> }
> break;
>
> default:
> for(
> BYTECOUNTER=0;BYTECOUNTER > *( pchar + BYTECOUNTER) = SPI_8bits_SINGLEIN();
> }
> break;
> }
> CS_PASSIVE;
>
> return request_command.var_length;
> }
>
> DWORD main(DWORD argc, BYTE *argv[]){
>
> DWORD BYTECOUNTER, RESULT, i, j, FILE_LENTGH, START_ADDRESS;
> BYTE *inBUFFER, DUMMY;
> FILE *lst;
>
> InitSystem();
>
> inBUFFER = (char *)malloc( 0x200000);
> if( inBUFFER == NULL){
> printf( "\n No free memory! \n");
> return 0;
> }
>
> switch( argc){
> case 2:
> if( strcmp( argv[1],"-e") == 0){
>
> //***********************************************************************//
> // //
>
> //***********************************************************************//
>
> printf( "Chip erase execute:\n");
> FLASHW25VF032B_Command_execute( WRITE_ENABLE, 0, NULL );
> FLASHW25VF032B_Command_execute( CHIP_ERASE, 0, NULL );
> do{
> FLASHW25VF032B_Command_execute( READ_STATUS_REG1,
> 0, &DUMMY);
> printf( "-");
> }while( (DUMMY & 0x01) == 1);
> printf( "\n");
> FLASHW25VF032B_Command_execute( WRITE_DISABLE, 0, NULL );
>
> }else if( strcmp( argv[1],"-st") == 0){
>
> //***********************************************************************//
> // //
>
> //***********************************************************************//
>
> RESULT = FLASHW25VF032B_Command_execute(
> READ_STATUS_REG1, 0, inBUFFER );
> printf( " REG1: ");
> for( BYTECOUNTER=0;BYTECOUNTER > printf( " %02X", *( inBUFFER + BYTECOUNTER));
> }
> printf( "\n");
>
> RESULT = FLASHW25VF032B_Command_execute(
> READ_STATUS_REG2, 0, inBUFFER );
> printf( " REG2: ");
> for( BYTECOUNTER=0;BYTECOUNTER > printf( " %02X", *( inBUFFER + BYTECOUNTER));
> }
> printf( "\n");
>
> }else if( strcmp( argv[1],"-id") == 0){
>
> //***********************************************************************//
> // //
>
> //***********************************************************************//
>
> RESULT = FLASHW25VF032B_Command_execute( MAN_DEVICE_ID,
> 0, inBUFFER );
> printf( " JEDEC: ");
> for( BYTECOUNTER=0;BYTECOUNTER > printf( " %02X", *( inBUFFER + BYTECOUNTER));
> }
> printf( "\n");
>
> }else if( strcmp( argv[1],"-ee") == 0){
>
> //***********************************************************************//
> // //
>
> //***********************************************************************//
>
> FLASHW25VF032B_Command_execute( WRITE_ENABLE, 0, NULL );
>
> *(inBUFFER + 0) = 0x00;
> *(inBUFFER + 1) = 0x00;
>
> FLASHW25VF032B_Command_execute( WRITE_STATUS_REG, 0,
> inBUFFER );
> FLASHW25VF032B_Command_execute( WRITE_DISABLE, 0,NULL );
>
> }else{
>
> //***********************************************************************//
> // //
>
> //***********************************************************************//
>
> printf( "Wrong option: %s\n", argv[1]);
> }
> break;
>
> case 4:
> if( strcmp( argv[1],"-r") == 0){
>
> //***********************************************************************//
> // //
>
> //***********************************************************************//
>
> START_ADDRESS = atoi(argv[2]);
> RESULT = FLASHW25VF032B_Command_execute( FAST_READ,
> START_ADDRESS, inBUFFER );
> lst = fopen( argv[3], "w+");
> if( lst == NULL){
> printf( "File creation error: %s\n", argv[3]);
> }else{
> for( BYTECOUNTER=0;BYTECOUNTER > fputc( *( inBUFFER + BYTECOUNTER), lst);
> }
> fclose( lst);
> }
>
> /*
> for( i=0; i > printf(" 0x%04X :", i << 4);
> for( j=0; j<16; j++){
> printf(" %02X", *( inBUFFER + i*16 + j));
> }
> printf("\n");
> }*/
> }else if( strcmp( argv[1],"-pr") == 0){
>
> //***********************************************************************//
> // //
>
> //***********************************************************************//
>
> lst = fopen( argv[3], "r+");
> if( lst == NULL){
> printf( "File read error: %s\n", argv[3]);
> }else{
> FILE_LENTGH = 0;
> while (!feof( lst)){
> *( inBUFFER + FILE_LENTGH) = fgetc( lst);
> FILE_LENTGH++;
> if( (FILE_LENTGH-1) > 0x200000){
> fclose( lst);
> printf( "Opened file is more then
> 0x200000!\n");
> break;
> }
> }
> fclose( lst);
> FILE_LENTGH -= 1;
> printf( "File length 0x%08X\n", FILE_LENTGH);
> FILE_LENTGH &= 0xFFFFF000;
> START_ADDRESS = atoi(argv[2]);
> for( i=0; i < FILE_LENTGH; i+=0x1000){
> printf( "ADDRESS 0x%08X\n", i + START_ADDRESS);
> FLASHW25VF032B_Command_execute( WRITE_ENABLE,
> 0,NULL );
> FLASHW25VF032B_Command_execute( EBSY, 0,NULL );
> FLASHW25VF032B_Command_execute(
> AAI_Word_Program, (DWORD)i + START_ADDRESS, (inBUFFER + i));
> FLASHW25VF032B_Command_execute( WRITE_DISABLE,
> 0, NULL );
> FLASHW25VF032B_Command_execute( DBSY, 0,NULL );
> }
> printf( "\n");
> }
> }else{
>
> //***********************************************************************//
> // //
>
> //***********************************************************************//
>
> printf( "Wrong option: %s\n", argv[1]);
> }
> break;
> default:
> printf( "Need more arguments!\n");
> break;
> }
> free( inBUFFER);
> return 0;
> }
>
> With my best regards,
>
> Alex
>
> On 10/22/2010 10:59, ?? wrote:
> >
> > help!!
> >
> >
> > ----- Original Message -----
> > From: ??
> > To: m...
>
> > Sent: Friday, October 22, 2010 10:54 PM
> > Subject: [msp430] how SST25VF010 driver for MSP430 SPI
> >
> >
> >
> > I used MSP430F5XX's SPI Module,in master
> > I can make it works with SST25VF010 flash chip
> > but i used IO simulation SPI,it does work!!!
> >
> > who can tell me why?
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>
>



Memfault Beyond the Launch