hpw421初始版本
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
/*!
|
||||
* \file main.c
|
||||
*
|
||||
* \brief Target main implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Func Prototype
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
void clock_init(void)
|
||||
{
|
||||
CLOCK_InitCfg_t clock_cfg;
|
||||
|
||||
clock_cfg.hfclk_src = CLOCK_HFCLK_SRC_XTAL;
|
||||
clock_cfg.hfclk_in = CLOCK_HFCLK_IN_32M;
|
||||
clock_cfg.lfclk_src = CLOCK_LFCLK_SRC_RC;
|
||||
|
||||
if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_XTAL) {
|
||||
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32768;
|
||||
} else if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_RC) {
|
||||
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32K;
|
||||
}
|
||||
|
||||
xc_clock_init_cfg(&clock_cfg);
|
||||
|
||||
SysTick_Config(xc_clock_hfclk_in_get() / 100);
|
||||
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
|
||||
}
|
||||
|
||||
void app_uart_init(void)
|
||||
{
|
||||
GPIO_InitCfg_t gpio_cfg = {0};
|
||||
|
||||
gpio_cfg.Mux = GPIO_Mux0;
|
||||
gpio_cfg.Pull = GPIO_PULLUP;
|
||||
gpio_cfg.Int = NOT_INT;
|
||||
gpio_cfg.FunSel = UART0_TX;
|
||||
|
||||
gpio_cfg.Pin = GPIO_18;
|
||||
gpio_cfg.Dir = GPIO_DIR_OUTPUT;
|
||||
xc_gpio_init(&gpio_cfg);
|
||||
|
||||
gpio_cfg.FunSel = UART0_RX;
|
||||
gpio_cfg.Pin = GPIO_19;
|
||||
gpio_cfg.Dir = GPIO_DIR_INPUT;
|
||||
xc_gpio_init(&gpio_cfg);
|
||||
|
||||
UART_InitCfg_t uart_cfg = {0};
|
||||
|
||||
uart_cfg.Parity = UART_PARITY_DISABLE;
|
||||
uart_cfg.StopBits = UART_STOP_1_BITS;
|
||||
uart_cfg.WordLength = UART_DATA_8_BITS;
|
||||
uart_cfg.BaudRate = UART_BAUDRATE_115200;
|
||||
uart_cfg.HardwareFlowControl = UART_HWFC_DISABLE;
|
||||
|
||||
xc_uart_init(UART0_IDX, &uart_cfg);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
// Clock Initialization
|
||||
clock_init();
|
||||
|
||||
app_uart_init();
|
||||
|
||||
DEBUG("__START__\n");
|
||||
/* spi_dma_master demo */
|
||||
spi_dma_master_demo();
|
||||
|
||||
while (1) {
|
||||
/* main loop */
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*!
|
||||
* \file spi_master.c
|
||||
*
|
||||
* \brief Target spi master device implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "spi_master.h"
|
||||
#include "xc_drv_fmc_spi_dma.h"
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------------------------------------------------*/
|
||||
#define MS_BUFFER_LEN 64U
|
||||
#define MS_NODMA_BUFFER_LEN 16U
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
volatile uint8_t m_wr_buff[MS_BUFFER_LEN] = {0};
|
||||
volatile uint8_t m_rd_buff[MS_BUFFER_LEN] = {0};
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
****************************************************************************************
|
||||
* @brief
|
||||
*
|
||||
* @param[in]
|
||||
* @param[in]
|
||||
|
||||
* @return[out]
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
void spi_dma_master_demo(void)
|
||||
{
|
||||
DEBUG("__SPI_DMA_MASTER_DEMO__\n");
|
||||
|
||||
GPIO_InitCfg_t gpio_cfg = {0};
|
||||
|
||||
gpio_cfg.Mux = GPIO_Mux0;
|
||||
gpio_cfg.Dir = GPIO_DIR_OUTPUT ;
|
||||
gpio_cfg.FunSel = SSI1_CLK;
|
||||
gpio_cfg.Int = NOT_INT;
|
||||
gpio_cfg.Pull = GPIO_PULLDOWN;
|
||||
gpio_cfg.Pin = GPIO_5;
|
||||
xc_gpio_init( &gpio_cfg );
|
||||
|
||||
gpio_cfg.FunSel = SSI1_SSN;
|
||||
gpio_cfg.Pin = GPIO_15;
|
||||
xc_gpio_init( &gpio_cfg );
|
||||
|
||||
gpio_cfg.FunSel = SSI1_TX;
|
||||
gpio_cfg.Pin = GPIO_16;
|
||||
xc_gpio_init( &gpio_cfg );
|
||||
|
||||
gpio_cfg.Dir = GPIO_DIR_INPUT ;
|
||||
gpio_cfg.FunSel = SSI1_RX;
|
||||
gpio_cfg.Pin = GPIO_17;
|
||||
xc_gpio_init( &gpio_cfg );
|
||||
|
||||
uint8_t spi_idx = SPI1_IDX;
|
||||
SPI_InitCfg_t spi_cfg = {0};
|
||||
|
||||
spi_cfg.Mode = SPI_MODE_MASTER;
|
||||
spi_cfg.DataSize = SSI_CTRL0_DFS_LEN_8BIT;
|
||||
spi_cfg.Direction = SSI_CTRL0_TMOD_WR;
|
||||
spi_cfg.BaudRatePrescaler = SSI_BAUD_DIV_8;
|
||||
spi_cfg.CLKPolarity = SSI_CTRL0_SCPOL_LOW;
|
||||
spi_cfg.CLKPhase = SSI_CTRL0_SCPHA_TRAIL;
|
||||
spi_cfg.FirstBit = SPI_FirstBit_MSB;
|
||||
|
||||
xc_spi_init(spi_idx, &spi_cfg);
|
||||
NVIC_EnableIRQ(DMA_IRQn);
|
||||
|
||||
memset((uint8_t *)m_wr_buff, 0x55, sizeof(m_wr_buff));
|
||||
DEBUG("Write buffer: \n");
|
||||
for(uint16_t i = 0; i<sizeof(m_wr_buff); i++)
|
||||
{
|
||||
PRINT("%02x ", m_wr_buff[i]);
|
||||
}
|
||||
PRINT("\n");
|
||||
|
||||
xc_spi_dma_write_and_read_data(spi_idx,
|
||||
(uint8_t *)m_wr_buff, sizeof(m_wr_buff),
|
||||
(uint8_t *)m_rd_buff, sizeof(m_rd_buff));
|
||||
|
||||
DEBUG("__SPI_READ_END__\n");
|
||||
for(uint16_t i = 0; i<sizeof(m_rd_buff); i++)
|
||||
{
|
||||
PRINT("%02x ", m_rd_buff[i]);
|
||||
}
|
||||
PRINT("\n");
|
||||
|
||||
delay_ms(1000);//wait slave device into recieve status
|
||||
|
||||
memset((uint8_t *)m_wr_buff, 0xaa, sizeof(m_wr_buff));
|
||||
xc_spi_dma_write_and_read_data(spi_idx,
|
||||
(uint8_t *)m_wr_buff, sizeof(m_wr_buff),
|
||||
(uint8_t *)m_rd_buff, sizeof(m_rd_buff));
|
||||
DEBUG("__SPI_READ_END2__\n");
|
||||
for(uint16_t i = 0; i<sizeof(m_rd_buff); i++)
|
||||
{
|
||||
PRINT("%02x ", m_rd_buff[i]);
|
||||
}
|
||||
PRINT("\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user