共2条
1/1 1 跳转至页
SPI,AT45DB161 SPI口接AT45DB161
问
MSP430F149的SPI口接AT45DB161FLASH读写总是出错误,不知哪位用过?请能提点建议。
答 1:
这个不是SPI方式的,不知道有没有用,以前别人给的
答 2:
#include "MSP430x44x.h"
//
// MSP430F449
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|- ________
// | | | |
// | P6.0|-->| A |
// | P6.1| . | T |
// | P6.2| . | 4 |
// | P6.3| . | 5 |
// | P6.4| . | D |
// | P6.5| . | B |
// | P6.6|-->| 0 |
// | | | 4 |
// | | | 1 |
// |________|
//
//本实验是将TAB中的数据写入AT45DB041中
//在将数据从AT45DB041读出,
//并将数据放入250为首地址的RAM中
int word;
int cmd_word;
int R_word;
int tab[16]={0x21,0x22,0x23,0x24,0x25,0x26};
int *Ram_addr;
int *Buff_addr;
void Send_Byte(void)
{
int i;
int Tamp;
for (i=0;i<8;i++)
{
P6OUT &= 0xDF;
Tamp = word;
Tamp &= 0x80;
if(!Tamp)
P6OUT &= 0xEF;
else
P6OUT |= 0x10;
P6OUT |= 0x20;
word = word << 1;
}
}
void Send_Start(void)
{
P6DIR |= 0X30;
P6OUT |= 0X20;
word = cmd_word;
Send_Byte();
}
void Stop(void)
{
P6DIR &= 0X00;
P6DIR |= 0X63;
P6OUT |= 0X63;
}
void Flash_B_Write(void)
{
int j;
P6DIR |= 0X40;
P6OUT &= 0XBF;
cmd_word = 0x84;
Send_Start();
word = 0x00;
Send_Byte();
word = 0x00;
Send_Byte();
word = 0x1A;
Send_Byte();
for(j=0;j<16;j++)
{
word = tab[j];
Send_Byte();
}
Buff_addr = (int *)0x1A;
Stop();
}
void Receive_Byte(void)
{
int i;
P6DIR |= 0X20;
P6DIR &= 0XF7;
R_word = 0x00;
P6OUT &= 0xBF;
for(i=0;i<8;i++)
{
P6OUT &= 0xDF;
P6OUT |= 0X20;
if(P6IN & 0x08)
R_word |= 0x01;
else
R_word &= 0xFE;
P6OUT &= 0xDF;
R_word = R_word << 1;
}
R_word = R_word >> 1;
}
void Flash_B_Read(void)
{
int j;
P6DIR |= 0X40;//CS out
P6OUT &= 0XBF;
cmd_word = 0x54;
Send_Start();
word = 0x00;
Send_Byte();
word = 0x00;
Send_Byte();
word = 0x1A;
Send_Byte();
word = 0xff;
Send_Byte();
for(j=0;j<16;j++)
{
Receive_Byte();
*Ram_addr++ = R_word;
}
Stop();
}
void main(void)
{
while(1){
int m = 0x7fff;
WDTCTL = WDTPW + WDTHOLD;
FLL_CTL1 = SELM_A + FLL_DIV_8;
P6DIR &= 0X00;
P6SEL &= 0X00;
P6DIR |= 0X63;
P6OUT |= 0X63;
Flash_B_Write();
while(m-- > 0);
Ram_addr = (int *)0x270;
Flash_B_Read();
}
} 答 3: 楼上程序应该是没有问题,这是TEST44X学习板里的实验程序。 答 4: 谢谢各位修改等待的判别语句后,成功读写SPI。
TXBUF1 = 0xff;
while ((UTCTL1&0X01)==0);
buffer_data[i]=RXBUF1; 答 5: 还有一个问题,虽然可从软件处理,但不知是什么原因?即第一次无论是开机或是调试RESET后,片选读SPI FLASH总是不正确,第二次及以后再读即正确,不知是否有人遇到类似的问题?
//
// MSP430F449
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|- ________
// | | | |
// | P6.0|-->| A |
// | P6.1| . | T |
// | P6.2| . | 4 |
// | P6.3| . | 5 |
// | P6.4| . | D |
// | P6.5| . | B |
// | P6.6|-->| 0 |
// | | | 4 |
// | | | 1 |
// |________|
//
//本实验是将TAB中的数据写入AT45DB041中
//在将数据从AT45DB041读出,
//并将数据放入250为首地址的RAM中
int word;
int cmd_word;
int R_word;
int tab[16]={0x21,0x22,0x23,0x24,0x25,0x26};
int *Ram_addr;
int *Buff_addr;
void Send_Byte(void)
{
int i;
int Tamp;
for (i=0;i<8;i++)
{
P6OUT &= 0xDF;
Tamp = word;
Tamp &= 0x80;
if(!Tamp)
P6OUT &= 0xEF;
else
P6OUT |= 0x10;
P6OUT |= 0x20;
word = word << 1;
}
}
void Send_Start(void)
{
P6DIR |= 0X30;
P6OUT |= 0X20;
word = cmd_word;
Send_Byte();
}
void Stop(void)
{
P6DIR &= 0X00;
P6DIR |= 0X63;
P6OUT |= 0X63;
}
void Flash_B_Write(void)
{
int j;
P6DIR |= 0X40;
P6OUT &= 0XBF;
cmd_word = 0x84;
Send_Start();
word = 0x00;
Send_Byte();
word = 0x00;
Send_Byte();
word = 0x1A;
Send_Byte();
for(j=0;j<16;j++)
{
word = tab[j];
Send_Byte();
}
Buff_addr = (int *)0x1A;
Stop();
}
void Receive_Byte(void)
{
int i;
P6DIR |= 0X20;
P6DIR &= 0XF7;
R_word = 0x00;
P6OUT &= 0xBF;
for(i=0;i<8;i++)
{
P6OUT &= 0xDF;
P6OUT |= 0X20;
if(P6IN & 0x08)
R_word |= 0x01;
else
R_word &= 0xFE;
P6OUT &= 0xDF;
R_word = R_word << 1;
}
R_word = R_word >> 1;
}
void Flash_B_Read(void)
{
int j;
P6DIR |= 0X40;//CS out
P6OUT &= 0XBF;
cmd_word = 0x54;
Send_Start();
word = 0x00;
Send_Byte();
word = 0x00;
Send_Byte();
word = 0x1A;
Send_Byte();
word = 0xff;
Send_Byte();
for(j=0;j<16;j++)
{
Receive_Byte();
*Ram_addr++ = R_word;
}
Stop();
}
void main(void)
{
while(1){
int m = 0x7fff;
WDTCTL = WDTPW + WDTHOLD;
FLL_CTL1 = SELM_A + FLL_DIV_8;
P6DIR &= 0X00;
P6SEL &= 0X00;
P6DIR |= 0X63;
P6OUT |= 0X63;
Flash_B_Write();
while(m-- > 0);
Ram_addr = (int *)0x270;
Flash_B_Read();
}
} 答 3: 楼上程序应该是没有问题,这是TEST44X学习板里的实验程序。 答 4: 谢谢各位修改等待的判别语句后,成功读写SPI。
TXBUF1 = 0xff;
while ((UTCTL1&0X01)==0);
buffer_data[i]=RXBUF1; 答 5: 还有一个问题,虽然可从软件处理,但不知是什么原因?即第一次无论是开机或是调试RESET后,片选读SPI FLASH总是不正确,第二次及以后再读即正确,不知是否有人遇到类似的问题?
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |