|
调试SPI通讯时发现一个奇怪的现象,加法加的数会自动加双倍,比如a+1输出的结果值是a+2的值.例如下方图中buf每次递增1,cmd[0]是buf,cmd[1]是buf+1,cmd[2]是buf+2,每次输出cmd数组,
用的是e2studio,只操作hal_entry.c文件,hal_entry.c里相关程序也贴在后面了,
整个项目打包在附件里了[url=]05_SPI.rar[/url]
#include "hal_data.h"
volatile unsigned char t10ms_cnt = 0;
volatile unsigned char buf = 0;
FSP_CPP_HEADER
void R_BSP_WarmStart(bsp_warm_start_event_t event);
FSP_CPP_FOOTER
void timer0_callback(timer_callback_args_t *p_args)
{
if(p_args->event == TIMER_EVENT_CYCLE_END)
t10ms_cnt ++;
if(t10ms_cnt%2)
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_00, BSP_IO_LEVEL_LOW);
else
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_00, BSP_IO_LEVEL_HIGH);
}
volatile bool g_transfer_complete = false;
void spi_callback (spi_callback_args_t * p_args)
{
if (SPI_EVENT_TRANSFER_COMPLETE == p_args->event)
{
g_transfer_complete = true;
}
}
/*******************************************************************************************************************//**
* main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function
* is called by main() when no RTOS is used.
**********************************************************************************************************************/
void hal_entry(void)
{
unsigned char cmd[3];
/* TODO: add your own code here */
R_GPT_Open(&g_timer0_ctrl, &g_timer0_cfg); //初始化定时器模块
R_GPT_Start(&g_timer0_ctrl); //启动GPT定时器
R_SPI_Open(&g_spi0_ctrl, &g_spi0_cfg); //开启SPI
while(1)
{
if(t10ms_cnt>=100)
{
t10ms_cnt = 0;
buf++;
// SPI模块 数据 长度 传输位数(8bit,16bit,32bit)
cmd[0] = buf;
cmd[1] = (unsigned char)(buf+1);
cmd[2] = (unsigned char)(buf+2);
R_SPI_Write(&g_spi0_ctrl, cmd, 3, SPI_BIT_WIDTH_8_BITS);
}
}
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
}
/*******************************************************************************************************************//**
* This function is called at various points during the startup process. This implementation uses the event that is
* called right before main() to set up the pins.
*
* @param[in] event Where at in the start up process the code is currently at
**********************************************************************************************************************/
void R_BSP_WarmStart(bsp_warm_start_event_t event)
{
if (BSP_WARM_START_RESET == event)
{
#if BSP_FEATURE_FLASH_LP_VERSION != 0
/* Enable reading from data flash. */
R_FACI_LP->DFLCTL = 1U;
/* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
* C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
#endif
}
if (BSP_WARM_START_POST_C == event)
{
/* C runtime environment and system clocks are setup. */
/* Configure pins. */
R_IOPORT_Open (&g_ioport_ctrl, g_ioport.p_cfg);
}
}
#if BSP_TZ_SECURE_BUILD
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();
/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ()
{
}
#endif
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|