后面就是循环读取的操作了。
/* while there is data to be read */
while(num_byte_to_read--){
/* read a byte from the flash */
*pbuffer = spi_flash_send_byte(DUMMY_BYTE);
/* point to the next location where the byte read will be saved */
pbuffer++;
}
怎么循环读取?
直接对flash发送一个DUMMY_BYTE(0xFF)的指令就可以了,然后呢,这个函数返回的就是所要读取的数据,你按照顺序读取的话,就读到对应地址开始的顺序数据了,就跟读文件一样,一直往下读了。
这里有两个以为,有人说,为什么要发送0xFF呢?其实发什么都可以,这个不用管,-_-||
最后来看下spi_flash_send_byte这个函数
就前面贴的这个函数,里面有注释可以大概看下,
主要的就是这一句代码:
/* send byte through the SPI1 peripheral */
spi_i2s_data_transmit(SPI1,byte);
和下面这句代码,-_-||,净说些废话,总共4句,两句重要
/* return the byte read from the SPI bus */
return(spi_i2s_data_receive(SPI1));
先看transmit,发送数据的这句:
这函数的实现:
/*!
\brief SPI transmit data
\param[in] spi_periph: SPIx(x=0,1,2)
\param[in] data: 16-bit data
\param[out] none
\retval none
*/
void spi_i2s_data_transmit(uint32_t spi_periph, uint16_t data)
{
SPI_DATA(spi_periph) = (uint32_t)data;
}
很简单,就是在一个寄存器上写一个数据,没猜错的话
再看另外一个接收函数实现:
/*!
\brief SPI receive data
\param[in] spi_periph: SPIx(x=0,1,2)
\param[out] none
\retval 16-bit data
*/
uint16_t spi_i2s_data_receive(uint32_t spi_periph)
{
return ((uint16_t)SPI_DATA(spi_periph));
}
在同样的寄存器上读取数据,这个是什么依据呢?
|