打印
[活动专区]

【AT-START-F425测评】+ SPI接口Flash读写测试

[复制链接]
649|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ar, pi, AD, ADXL, CD, RS
    找到以前做的一块扩展外设功能板,利用AT32F425先测试一下SPI接口的FLASH。紫色那个是自己以前做的扩展板。
板上带有SPI FLASH,TF卡座;
SPI接口的2.4寸tftlcd,带电阻触摸XT2046;
I2C接口的加速度传感器ADXL345.光照传感器rpr-0521rs。
外加几个按键和轴了。



下面先测试下FLASH,型号是W25Q128。
扩展板SPI flash接口如下,

下面找到AT-START-F425开发板对应的引脚如下。

对应:

FLASH CS = PB3
FLASH SCK = PA5
FLASH MISO = PA6
FLASH MOSI = PA7

在AT-START-F425开发板的资料例程找到了一个flash例程。修改了一下cs的管教。基本就可以用的。
主要代码:
#include "at32f425_board.h"
#include "at32f425_clock.h"
#include "at32f425_int.h"
#include "spi_flash.h"

/** @addtogroup AT32F425_periph_examples
  * @{
  */
void _delay_ms(uint32_t ms)
{
    uint32_t g_ms_tick;
    g_ms_tick = hal_get_tick();
    while(hal_get_tick() - g_ms_tick < ms);
}

/**
  * [url=home.php?mod=space&uid=247401]@brief[/url]  systick interrupt handler.
  * @param  none
  * @retval none
  */
void systick_handler(void)
{

}

#define FLASH_TEST_ADDR                  0x1000
#define BUF_SIZE                         0x500

uint8_t tx_buffer[BUF_SIZE];
uint8_t rx_buffer[BUF_SIZE];
volatile error_status transfer_status = ERROR;

void tx_data_fill(void);
error_status buffer_compare(uint8_t* pbuffer1, uint8_t* pbuffer2, uint16_t buffer_length);

/**
  * @brief  transfer data fill.
  * @param  none
  * @retval none
  */
void tx_data_fill(void)
{
    uint32_t data_index = 0;
    for(data_index = 0; data_index < BUF_SIZE; data_index++)
    {
        tx_buffer[data_index] = data_index+0X55;
    }
}

/**
  * @brief  buffer compare function.
  * @param  pbuffer1, pbuffer2: buffers to be compared.
  * @param  buffer_length: buffer's length
  * @retval the result of compare
  */
error_status buffer_compare(uint8_t* pbuffer1, uint8_t* pbuffer2, uint16_t buffer_length)
{
    while(buffer_length--)
    {
        if(*pbuffer1 != *pbuffer2)
        {
            return ERROR;
        }

        pbuffer1++;
        pbuffer2++;
    }
    return SUCCESS;
}

/**
  * @brief  main function.
  * @param  none
  * @retval none
  */
int main(void)
{
    __IO uint32_t index = 0;
    __IO uint32_t flash_id_index = 0;

    system_clock_config();
    /* config systick clock source */
    systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV);
    /* config systick reload value and enable interrupt */
    SysTick_Config(system_core_clock / 1000);
    /* configure led */
    at32_led_init(LED2);
    at32_led_init(LED3);
    uart_print_init(115200);
    printf("AT32F425 Test\r\n");
   

    tx_data_fill();
    spiflash_init();
    flash_id_index = spiflash_read_id();
    if(flash_id_index != W25Q128)
    {
        printf("flash id check error!\r\n");
        for(index = 0; index < 50; index++)
        {
            at32_led_toggle(LED2);
            at32_led_toggle(LED3);
            _delay_ms(200);
        }
        return 1;
    }
    else
    {
        printf("flash id check success! id: %X\r\n", flash_id_index);
    }

    /* erase sector */
    spiflash_sector_erase(FLASH_TEST_ADDR / SPIF_SECTOR_SIZE);

    /* write data */
    spiflash_write(tx_buffer, FLASH_TEST_ADDR, BUF_SIZE);

    /* read data */
    spiflash_read(rx_buffer, FLASH_TEST_ADDR, BUF_SIZE);

    /* printf read data */
    printf("Read Data: ");
    for(index = 0; index < BUF_SIZE; index++)
    {
        printf("%02X ", rx_buffer[index]);
    }

    /* test result:the data check */
    transfer_status = buffer_compare(rx_buffer, tx_buffer, BUF_SIZE);

    /* test result indicate:if SUCCESS ,led2 lights */
    if(transfer_status == SUCCESS)
    {
        printf("\r\nflash data read write success!\r\n");
        at32_led_on(LED2);
    }
    else
    {
        printf("\r\nflash data read write ERROR!\r\n");
        at32_led_off(LED2);
    }
   
    while(1)
    {
    }
}
通过串口输出信息:

测试读写成功,型号标志EF17.对应W25Q128.



使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

115

主题

4370

帖子

25

粉丝