又是4天,昨晚师兄说进度太慢,今天一天开挂,终于把FLASH搞定了。spi代码很短,一晚就写完,但是debug就用了两天多。
flash 的储存模式以不同,flash 写的时候只能写0,1就不用写,所以一开始要先擦除(erase),使所有位都变成1.擦除是又有4种模式,4k,32k,64k和全部擦除(chip erase)。
(测试: mcu:msp430f149 , flash:W25Q64BV ;对应引脚已在文件说明)
以下是代码:
#ifndef SPI_H_
#define SPI_H_
#include <msp430x14x.h>
#define SI_1 (P6OUT |= BIT7)
#define SI_0 (P6OUT &= ~BIT7)
#define SO_1 (P6OUT |= BIT5)
#define SO_0 (P6OUT &= ~BIT5)
#define SCK_1 (P2OUT |= BIT2)
#define SCK_0 (P2OUT &= ~BIT2)
#define SS_1 (P6OUT |= BIT6)
#define SS_0 (P6OUT &= ~BIT6)
void Delay(void);
void Init_SPI(void);
void Writebyte(unsigned char wdata);
unsigned char Readbyte(void);
#endif
#include <msp430x14x.h>
#include "SPI.h"
void Init_SPI(void)
{
}
void Delay(void)
{
}
void Writebyte(unsigned char wdata)
{
}
unsigned char Readbyte (void)
{
}
#ifndef W25Q64B_H_
#define W25Q64B_H_
void ReadNbyte(unsigned char Haddr,unsigned char Maddr,unsigned char Laddr,unsigned char *rbuff, unsigned int n);
void Erase(unsigned char era,unsigned char Haddr,unsigned char Maddr,unsigned char Laddr);
void WriteNbyte(unsigned char Haddr,unsigned char Maddr,unsigned char Laddr,unsigned char *wbuff,unsigned int n);
#endif
#include "SPI.h"
#include "w25q64b.h"
void WriteNbyte (unsigned char Haddr,unsigned char Maddr,unsigned char Laddr,unsigned char *wbuff,unsigned int n)
{
}
void ReadNbyte (unsigned char Haddr,unsigned char Maddr,unsigned char Laddr,unsigned char *rbuff,unsigned int n)
{
}
void Erase(unsigned char era,unsigned char Haddr,unsigned char Maddr,unsigned char Laddr)
{
}
#include <msp430x14x.h>
#include "SPI.h"
#include "w25q64b.h"
unsigned char Rbuff[10];
void Init_clk(void)
{
}
void main()
{
}
(2012-08-10 22:33:21)