mirror of
https://github.com/ArteryTek/AT32F415_Firmware_Library.git
synced 2026-05-21 09:22:11 +00:00
update version to v2.1.7
This commit is contained in:
@@ -8,10 +8,11 @@
|
||||
this demo is based on the at-start board, in this demo, shows in halfduplex
|
||||
mode how to use dma transfer data.
|
||||
the pins connection as follow:
|
||||
- pb0 as mck out
|
||||
- pb6 as mck out
|
||||
- i2s2 slaver i2s1 master
|
||||
- pb12 <---> pa4(ws)
|
||||
- pb13 <---> pa5(ck)
|
||||
- pb15 <---> pa7(sd)
|
||||
- pb12 <---> pa15(ws)
|
||||
- pb13 <---> pb3(ck)
|
||||
- pb15 <---> pb5(sd)
|
||||
|
||||
for more detailed information. please refer to the application note document AN0102.
|
||||
|
||||
for more detailed information. please refer to the application note document AN0102.
|
||||
@@ -44,10 +44,6 @@ uint16_t i2s1_buffer_tx[32] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C,
|
||||
uint16_t i2s2_buffer_rx[32];
|
||||
volatile error_status transfer_status = ERROR;
|
||||
|
||||
static void gpio_config(void);
|
||||
static void i2s_config(void);
|
||||
error_status buffer_compare(uint16_t* pbuffer1, uint16_t* pbuffer2, uint16_t buffer_length);
|
||||
|
||||
/**
|
||||
* @brief buffer_compare function.
|
||||
* @param none
|
||||
@@ -69,17 +65,17 @@ error_status buffer_compare(uint16_t* pbuffer1, uint16_t* pbuffer2, uint16_t buf
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief i2s configuration.
|
||||
* @brief dma configuration.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
static void i2s_config(void)
|
||||
static void dma_config(void)
|
||||
{
|
||||
dma_init_type dma_init_struct;
|
||||
i2s_init_type i2s_init_struct;
|
||||
|
||||
crm_periph_clock_enable(CRM_DMA1_PERIPH_CLOCK, TRUE);
|
||||
dma_reset(DMA1_CHANNEL4);
|
||||
|
||||
/* use dma1_channel3 as spi1 transmit channel */
|
||||
dma_reset(DMA1_CHANNEL3);
|
||||
dma_default_para_init(&dma_init_struct);
|
||||
dma_init_struct.buffer_size = 32;
|
||||
@@ -93,15 +89,36 @@ static void i2s_config(void)
|
||||
dma_init_struct.priority = DMA_PRIORITY_HIGH;
|
||||
dma_init_struct.loop_mode_enable = FALSE;
|
||||
dma_init(DMA1_CHANNEL3, &dma_init_struct);
|
||||
|
||||
|
||||
/* use dma1_channel4 as spi2 receive channel */
|
||||
dma_reset(DMA1_CHANNEL4);
|
||||
dma_init_struct.buffer_size = 32;
|
||||
dma_init_struct.direction = DMA_DIR_PERIPHERAL_TO_MEMORY;
|
||||
dma_init_struct.memory_base_addr = (uint32_t)i2s2_buffer_rx;
|
||||
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_HALFWORD;
|
||||
dma_init_struct.memory_inc_enable = TRUE;
|
||||
dma_init_struct.peripheral_base_addr = (uint32_t)&(SPI2->dt);
|
||||
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_HALFWORD;
|
||||
dma_init_struct.peripheral_inc_enable = FALSE;
|
||||
dma_init_struct.priority = DMA_PRIORITY_HIGH;
|
||||
dma_init_struct.loop_mode_enable = FALSE;
|
||||
dma_init(DMA1_CHANNEL4, &dma_init_struct);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief i2s configuration.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
static void i2s_config(void)
|
||||
{
|
||||
i2s_init_type i2s_init_struct;
|
||||
|
||||
/* master i2s initialization */
|
||||
crm_periph_clock_enable(CRM_SPI1_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_SPI2_PERIPH_CLOCK, TRUE);
|
||||
i2s_default_para_init(&i2s_init_struct);
|
||||
|
||||
/* master transmission mode */
|
||||
i2s_init_struct.audio_protocol = I2S_AUDIO_PROTOCOL_PHILLIPS;
|
||||
i2s_init_struct.data_channel_format = I2S_DATA_16BIT_CHANNEL_32BIT;
|
||||
i2s_init_struct.mclk_output_enable = TRUE;
|
||||
@@ -109,14 +126,27 @@ static void i2s_config(void)
|
||||
i2s_init_struct.clock_polarity = I2S_CLOCK_POLARITY_LOW;
|
||||
i2s_init_struct.operation_mode = I2S_MODE_MASTER_TX;
|
||||
i2s_init(SPI1, &i2s_init_struct);
|
||||
|
||||
i2s_init_struct.operation_mode =I2S_MODE_SLAVE_RX;
|
||||
|
||||
/* use dma transmit */
|
||||
spi_i2s_dma_transmitter_enable(SPI1, TRUE);
|
||||
|
||||
i2s_enable(SPI1, TRUE);
|
||||
|
||||
/* slave i2s initialization */
|
||||
crm_periph_clock_enable(CRM_SPI2_PERIPH_CLOCK, TRUE);
|
||||
|
||||
/* slave reception mode */
|
||||
i2s_init_struct.audio_protocol = I2S_AUDIO_PROTOCOL_PHILLIPS;
|
||||
i2s_init_struct.data_channel_format = I2S_DATA_16BIT_CHANNEL_32BIT;
|
||||
i2s_init_struct.mclk_output_enable = TRUE;
|
||||
i2s_init_struct.audio_sampling_freq = I2S_AUDIO_FREQUENCY_48K;
|
||||
i2s_init_struct.clock_polarity = I2S_CLOCK_POLARITY_LOW;
|
||||
i2s_init_struct.operation_mode = I2S_MODE_SLAVE_RX;
|
||||
i2s_init(SPI2, &i2s_init_struct);
|
||||
|
||||
dma_channel_enable(DMA1_CHANNEL3, TRUE);
|
||||
dma_channel_enable(DMA1_CHANNEL4, TRUE);
|
||||
/* use dma receive */
|
||||
spi_i2s_dma_receiver_enable(SPI2, TRUE);
|
||||
i2s_enable(SPI1, TRUE);
|
||||
|
||||
i2s_enable(SPI2, TRUE);
|
||||
}
|
||||
|
||||
@@ -130,49 +160,54 @@ static void gpio_config(void)
|
||||
gpio_init_type gpio_initstructure;
|
||||
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
|
||||
gpio_pin_remap_config(SWJTAG_GMUX_010, TRUE);
|
||||
gpio_pin_remap_config(SPI1_MUX_01, TRUE);
|
||||
|
||||
/* master ws pin */
|
||||
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
/* master i2s ws pin */
|
||||
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_4;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_15;
|
||||
gpio_init(GPIOA, &gpio_initstructure);
|
||||
|
||||
/* master ck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_5;
|
||||
gpio_init(GPIOA, &gpio_initstructure);
|
||||
|
||||
/* master sd pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_7;
|
||||
gpio_init(GPIOA, &gpio_initstructure);
|
||||
|
||||
/* master mck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_0;
|
||||
/* master i2s ck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_3;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave ws pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_12;
|
||||
/* master i2s sd pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_5;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave ck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_13;
|
||||
/* master i2s mck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_6;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave sd pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_15;
|
||||
/* slave i2s ws pin */
|
||||
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_INPUT;
|
||||
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_12;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave i2s ck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_INPUT;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_13;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave i2s sd pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_INPUT;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_15;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
}
|
||||
|
||||
@@ -185,14 +220,25 @@ int main(void)
|
||||
{
|
||||
system_clock_config();
|
||||
at32_board_init();
|
||||
at32_led_off(LED2);
|
||||
at32_led_off(LED3);
|
||||
at32_led_off(LED4);
|
||||
at32_led_on(LED4);
|
||||
gpio_config();
|
||||
dma_config();
|
||||
i2s_config();
|
||||
spi_i2s_dma_transmitter_enable(SPI1, TRUE);
|
||||
|
||||
/* enable i2s slave dma to get data */
|
||||
dma_channel_enable(DMA1_CHANNEL4, TRUE);
|
||||
|
||||
/* enable i2s master dma to fill data */
|
||||
dma_channel_enable(DMA1_CHANNEL3, TRUE);
|
||||
|
||||
while(dma_flag_get(DMA1_FDT4_FLAG) == RESET);
|
||||
/* wait slave i2s data receive end */
|
||||
while(dma_flag_get(DMA1_FDT4_FLAG) == RESET)
|
||||
{
|
||||
}
|
||||
|
||||
/* wait master and slave idle when communication end */
|
||||
while(spi_i2s_flag_get(SPI1, SPI_I2S_BF_FLAG) != RESET);
|
||||
while(spi_i2s_flag_get(SPI2, SPI_I2S_BF_FLAG) != RESET);
|
||||
|
||||
/* test result:the data check */
|
||||
transfer_status = buffer_compare(i2s2_buffer_rx, i2s1_buffer_tx, 32);
|
||||
@@ -204,7 +250,7 @@ int main(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
at32_led_off(LED2);
|
||||
at32_led_on(LED3);
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
this demo is based on the at-start board, in this demo, shows in halfduplex
|
||||
mode how to use interrupt transfer data.
|
||||
the pins connection as follow:
|
||||
- pb0 as mck out
|
||||
- pb6 as mck out
|
||||
- i2s2 slaver i2s1 master
|
||||
- pb12 <---> pa4(ws)
|
||||
- pb13 <---> pa5(ck)
|
||||
- pb15 <---> pa7(sd)
|
||||
- pb12 <---> pa15(ws)
|
||||
- pb13 <---> pb3(ck)
|
||||
- pb15 <---> pb5(sd)
|
||||
|
||||
for more detailed information. please refer to the application note document AN0102.
|
||||
|
||||
for more detailed information. please refer to the application note document AN0102.
|
||||
@@ -24,11 +24,6 @@
|
||||
|
||||
/* includes ------------------------------------------------------------------*/
|
||||
#include "at32f415_int.h"
|
||||
#include "at32f415_board.h"
|
||||
|
||||
extern uint16_t i2s1_buffer_tx[];
|
||||
extern uint16_t i2s2_buffer_rx[];
|
||||
extern __IO uint32_t tx_index, rx_index;
|
||||
|
||||
/** @addtogroup AT32F415_periph_examples
|
||||
* @{
|
||||
@@ -135,37 +130,6 @@ void SysTick_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function handles the spi2 interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SPI2_IRQHandler(void)
|
||||
{
|
||||
if(spi_i2s_interrupt_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET)
|
||||
{
|
||||
i2s2_buffer_rx[rx_index++] = spi_i2s_data_receive(SPI2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles the spi1 interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SPI1_IRQHandler(void)
|
||||
{
|
||||
if(spi_i2s_interrupt_flag_get(SPI1, SPI_I2S_TDBE_FLAG) != RESET)
|
||||
{
|
||||
spi_i2s_data_transmit(SPI1, i2s1_buffer_tx[tx_index++]);
|
||||
if(tx_index == 32)
|
||||
{
|
||||
spi_i2s_interrupt_enable(SPI1, SPI_I2S_TDBE_INT, FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -44,11 +44,6 @@ uint16_t i2s2_buffer_rx[32];
|
||||
__IO uint32_t tx_index = 0, rx_index = 0;
|
||||
volatile error_status transfer_status1 = ERROR, transfer_status2 = ERROR;
|
||||
|
||||
static void gpio_config(void);
|
||||
static void i2s_config(i2s_data_channel_format_type format, i2s_audio_sampling_freq_type freq);
|
||||
error_status buffer_compare(uint16_t* pbuffer1, uint16_t* pbuffer2, uint16_t buffer_length);
|
||||
error_status buffer_compare_24bits(uint16_t* pbuffer1, uint16_t* pbuffer2, uint16_t buffer_length);
|
||||
|
||||
/**
|
||||
* @brief buffer_compare function.
|
||||
* @param none
|
||||
@@ -100,15 +95,14 @@ error_status buffer_compare_24bits(uint16_t* pbuffer1, uint16_t* pbuffer2, uint1
|
||||
static void i2s_config(i2s_data_channel_format_type format, i2s_audio_sampling_freq_type freq)
|
||||
{
|
||||
i2s_init_type i2s_init_struct;
|
||||
|
||||
|
||||
/* master i2s initialization */
|
||||
crm_periph_clock_enable(CRM_SPI1_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_SPI2_PERIPH_CLOCK, TRUE);
|
||||
|
||||
nvic_irq_enable(SPI1_IRQn, 0, 0);
|
||||
nvic_irq_enable(SPI2_IRQn, 0, 0);
|
||||
spi_i2s_reset(SPI2);
|
||||
spi_i2s_reset(SPI1);
|
||||
i2s_default_para_init(&i2s_init_struct);
|
||||
|
||||
/* master transmission mode */
|
||||
i2s_init_struct.audio_protocol = I2S_AUDIO_PROTOCOL_PHILLIPS;
|
||||
i2s_init_struct.data_channel_format = format;
|
||||
i2s_init_struct.mclk_output_enable = TRUE;
|
||||
@@ -116,14 +110,26 @@ static void i2s_config(i2s_data_channel_format_type format, i2s_audio_sampling_f
|
||||
i2s_init_struct.clock_polarity = I2S_CLOCK_POLARITY_LOW;
|
||||
i2s_init_struct.operation_mode = I2S_MODE_MASTER_TX;
|
||||
i2s_init(SPI1, &i2s_init_struct);
|
||||
|
||||
|
||||
/* enable transmit data buffer empty interrupt */
|
||||
spi_i2s_interrupt_enable(SPI1, SPI_I2S_TDBE_INT, TRUE);
|
||||
|
||||
/* slave i2s initialization */
|
||||
crm_periph_clock_enable(CRM_SPI2_PERIPH_CLOCK, TRUE);
|
||||
nvic_irq_enable(SPI2_IRQn, 0, 0);
|
||||
spi_i2s_reset(SPI2);
|
||||
|
||||
/* slave reception mode */
|
||||
i2s_init_struct.audio_protocol = I2S_AUDIO_PROTOCOL_PHILLIPS;
|
||||
i2s_init_struct.data_channel_format = format;
|
||||
i2s_init_struct.mclk_output_enable = TRUE;
|
||||
i2s_init_struct.audio_sampling_freq = freq;
|
||||
i2s_init_struct.clock_polarity = I2S_CLOCK_POLARITY_LOW;
|
||||
i2s_init_struct.operation_mode =I2S_MODE_SLAVE_RX;
|
||||
i2s_init(SPI2, &i2s_init_struct);
|
||||
|
||||
|
||||
/* enable receive data buffer full interrupt */
|
||||
spi_i2s_interrupt_enable(SPI2, SPI_I2S_RDBF_INT, TRUE);
|
||||
spi_i2s_interrupt_enable(SPI1, SPI_I2S_TDBE_INT, TRUE);
|
||||
i2s_enable(SPI2, TRUE);
|
||||
i2s_enable(SPI1, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,50 +142,85 @@ static void gpio_config(void)
|
||||
gpio_init_type gpio_initstructure;
|
||||
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
|
||||
gpio_pin_remap_config(SWJTAG_GMUX_010, TRUE);
|
||||
gpio_pin_remap_config(SPI1_MUX_01, TRUE);
|
||||
|
||||
/* master ws pin */
|
||||
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
/* master i2s ws pin */
|
||||
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_4;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_15;
|
||||
gpio_init(GPIOA, &gpio_initstructure);
|
||||
|
||||
/* master ck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_5;
|
||||
gpio_init(GPIOA, &gpio_initstructure);
|
||||
|
||||
/* master sd pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_7;
|
||||
gpio_init(GPIOA, &gpio_initstructure);
|
||||
|
||||
/* master mck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_0;
|
||||
/* master i2s ck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_3;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave ws pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_12;
|
||||
/* master i2s sd pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_5;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave ck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_13;
|
||||
/* master i2s mck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_6;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave sd pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_15;
|
||||
/* slave i2s ws pin */
|
||||
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_INPUT;
|
||||
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_12;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave i2s ck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_INPUT;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_13;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave i2s sd pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_INPUT;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_15;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief spi2 interrupt function
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void SPI2_IRQHandler(void)
|
||||
{
|
||||
if(spi_i2s_interrupt_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET)
|
||||
{
|
||||
i2s2_buffer_rx[rx_index++] = spi_i2s_data_receive(SPI2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief spi1 interrupt function
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void SPI1_IRQHandler(void)
|
||||
{
|
||||
if(spi_i2s_interrupt_flag_get(SPI1, SPI_I2S_TDBE_FLAG) != RESET)
|
||||
{
|
||||
spi_i2s_data_transmit(SPI1, i2s1_buffer_tx[tx_index++]);
|
||||
if(tx_index == 32)
|
||||
{
|
||||
spi_i2s_interrupt_enable(SPI1, SPI_I2S_TDBE_INT, FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,22 +234,45 @@ int main(void)
|
||||
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
||||
system_clock_config();
|
||||
at32_board_init();
|
||||
at32_led_off(LED2);
|
||||
at32_led_off(LED3);
|
||||
at32_led_off(LED4);
|
||||
at32_led_on(LED4);
|
||||
gpio_config();
|
||||
i2s_config(I2S_DATA_16BIT_CHANNEL_32BIT, I2S_AUDIO_FREQUENCY_48K);
|
||||
|
||||
/* enable slave and master i2s to start communication */
|
||||
i2s_enable(SPI2, TRUE);
|
||||
i2s_enable(SPI1, TRUE);
|
||||
|
||||
/* wait data receive end */
|
||||
while(rx_index < 32);
|
||||
|
||||
/* wait master and slave idle when communication end */
|
||||
while(spi_i2s_flag_get(SPI1, SPI_I2S_BF_FLAG) != RESET);
|
||||
while(spi_i2s_flag_get(SPI2, SPI_I2S_BF_FLAG) != RESET);
|
||||
|
||||
/* test result:the data check */
|
||||
transfer_status1 = buffer_compare(i2s2_buffer_rx, i2s1_buffer_tx, 32);
|
||||
|
||||
for(index = 0; index < 32; index++) i2s2_buffer_rx[index] = 0;
|
||||
/* receive buffer clear */
|
||||
tx_index = 0;
|
||||
rx_index = 0;
|
||||
|
||||
for(index = 0; index < 32; index++)
|
||||
{
|
||||
i2s2_buffer_rx[index] = 0;
|
||||
}
|
||||
|
||||
/* change frame format */
|
||||
i2s_config(I2S_DATA_24BIT_CHANNEL_32BIT, I2S_AUDIO_FREQUENCY_16K);
|
||||
|
||||
/* enable slave and master i2s to start communication */
|
||||
i2s_enable(SPI2, TRUE);
|
||||
i2s_enable(SPI1, TRUE);
|
||||
|
||||
/* wait data receive end */
|
||||
while(rx_index < 32);
|
||||
|
||||
/* wait master and slave idle when communication end */
|
||||
while(spi_i2s_flag_get(SPI1, SPI_I2S_BF_FLAG) != RESET);
|
||||
while(spi_i2s_flag_get(SPI2, SPI_I2S_BF_FLAG) != RESET);
|
||||
|
||||
/* test result:the data check */
|
||||
transfer_status2 = buffer_compare_24bits(i2s2_buffer_rx, i2s1_buffer_tx, 32);
|
||||
@@ -220,7 +284,7 @@ int main(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
at32_led_off(LED2);
|
||||
at32_led_on(LED3);
|
||||
}
|
||||
|
||||
while(1)
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
the pins connection as follow:
|
||||
- pb0 as mck out
|
||||
- i2s2 slaver i2s1 master
|
||||
- pb12 <---> pa4(ws)
|
||||
- pb13 <---> pa5(ck)
|
||||
- pb15 <---> pa7(sd)
|
||||
- pb12 <---> pa15(ws)
|
||||
- pb13 <---> pb3(ck)
|
||||
- pb15 <---> pb5(sd)
|
||||
|
||||
for more detailed information. please refer to the application note document AN0102.
|
||||
|
||||
for more detailed information. please refer to the application note document AN0102.
|
||||
@@ -34,6 +34,9 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define SPI_MASTER_CS_HIGH gpio_bits_set(GPIOA, GPIO_PINS_15)
|
||||
#define SPI_MASTER_CS_LOW gpio_bits_reset(GPIOA, GPIO_PINS_15)
|
||||
|
||||
uint16_t i2s1_buffer_tx[32] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C,
|
||||
0x0D0E, 0x0F10, 0x1112, 0x1314, 0x1516, 0x1718,
|
||||
0x191A, 0x1B1C, 0x1D1E, 0x1F20, 0x2122, 0x2324,
|
||||
@@ -41,7 +44,7 @@ uint16_t i2s1_buffer_tx[32] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C,
|
||||
0x3132, 0x3334, 0x3536, 0x3738, 0x393A, 0x3B3C,
|
||||
0x3D3E, 0x3F40
|
||||
};
|
||||
uint16_t SPI1_buffer_tx[32] = {0x5152, 0x5354, 0x5556, 0x5758, 0x595A, 0x5B5C,
|
||||
uint16_t spi1_buffer_tx[32] = {0x5152, 0x5354, 0x5556, 0x5758, 0x595A, 0x5B5C,
|
||||
0x5D5E, 0x5F60, 0x6162, 0x6364, 0x6566, 0x6768,
|
||||
0x696A, 0x6B6C, 0x6D6E, 0x6F70, 0x7172, 0x7374,
|
||||
0x7576, 0x7778, 0x797A, 0x7B7C, 0x7D7E, 0x7F80,
|
||||
@@ -53,11 +56,6 @@ uint16_t spi2_buffer_rx[32];
|
||||
__IO uint32_t tx_index = 0, rx_index = 0;
|
||||
volatile error_status transfer_status1 = ERROR, transfer_status2 = ERROR, transfer_status3 = ERROR;
|
||||
|
||||
static void gpio_config(void);
|
||||
static void spi_config(void);
|
||||
static void i2s_config(i2s_operation_mode_type i2s1_mode, i2s_operation_mode_type i2s2_mode);
|
||||
error_status buffer_compare(uint16_t* pbuffer1, uint16_t* pbuffer2, uint16_t buffer_length);
|
||||
|
||||
/**
|
||||
* @brief buffer_compare function.
|
||||
* @param none
|
||||
@@ -86,13 +84,12 @@ error_status buffer_compare(uint16_t* pbuffer1, uint16_t* pbuffer2, uint16_t buf
|
||||
static void i2s_config(i2s_operation_mode_type i2s1_mode, i2s_operation_mode_type i2s2_mode)
|
||||
{
|
||||
i2s_init_type i2s_init_struct;
|
||||
|
||||
|
||||
/* i2s1 initialization */
|
||||
crm_periph_clock_enable(CRM_SPI1_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_SPI2_PERIPH_CLOCK, TRUE);
|
||||
|
||||
spi_i2s_reset(SPI2);
|
||||
spi_i2s_reset(SPI1);
|
||||
i2s_default_para_init(&i2s_init_struct);
|
||||
|
||||
i2s_init_struct.audio_protocol = I2S_AUDIO_PROTOCOL_PHILLIPS;
|
||||
i2s_init_struct.data_channel_format = I2S_DATA_16BIT_CHANNEL_32BIT;
|
||||
i2s_init_struct.mclk_output_enable = FALSE;
|
||||
@@ -100,7 +97,15 @@ static void i2s_config(i2s_operation_mode_type i2s1_mode, i2s_operation_mode_typ
|
||||
i2s_init_struct.clock_polarity = I2S_CLOCK_POLARITY_LOW;
|
||||
i2s_init_struct.operation_mode = i2s1_mode;
|
||||
i2s_init(SPI1, &i2s_init_struct);
|
||||
|
||||
|
||||
/* i2s2 initialization */
|
||||
crm_periph_clock_enable(CRM_SPI2_PERIPH_CLOCK, TRUE);
|
||||
spi_i2s_reset(SPI2);
|
||||
i2s_init_struct.audio_protocol = I2S_AUDIO_PROTOCOL_PHILLIPS;
|
||||
i2s_init_struct.data_channel_format = I2S_DATA_16BIT_CHANNEL_32BIT;
|
||||
i2s_init_struct.mclk_output_enable = FALSE;
|
||||
i2s_init_struct.audio_sampling_freq = I2S_AUDIO_FREQUENCY_48K;
|
||||
i2s_init_struct.clock_polarity = I2S_CLOCK_POLARITY_LOW;
|
||||
i2s_init_struct.operation_mode =i2s2_mode;
|
||||
i2s_init(SPI2, &i2s_init_struct);
|
||||
}
|
||||
@@ -113,12 +118,13 @@ static void i2s_config(i2s_operation_mode_type i2s1_mode, i2s_operation_mode_typ
|
||||
static void spi_config(void)
|
||||
{
|
||||
spi_init_type spi_init_struct;
|
||||
|
||||
/* master spi initialization */
|
||||
crm_periph_clock_enable(CRM_SPI1_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_SPI2_PERIPH_CLOCK, TRUE);
|
||||
|
||||
spi_i2s_reset(SPI2);
|
||||
spi_i2s_reset(SPI1);
|
||||
spi_default_para_init(&spi_init_struct);
|
||||
|
||||
/* single line bidirectional half duplex mode-transmitting */
|
||||
spi_init_struct.transmission_mode = SPI_TRANSMIT_HALF_DUPLEX_TX;
|
||||
spi_init_struct.master_slave_mode =SPI_MODE_MASTER;
|
||||
spi_init_struct.mclk_freq_division = SPI_MCLK_DIV_8;
|
||||
@@ -128,68 +134,92 @@ static void spi_config(void)
|
||||
spi_init_struct.clock_phase = SPI_CLOCK_PHASE_2EDGE;
|
||||
spi_init_struct.cs_mode_selection = SPI_CS_SOFTWARE_MODE;
|
||||
spi_init(SPI1, &spi_init_struct);
|
||||
|
||||
|
||||
spi_enable(SPI1, TRUE);
|
||||
|
||||
/* slave spi initialization */
|
||||
crm_periph_clock_enable(CRM_SPI2_PERIPH_CLOCK, TRUE);
|
||||
spi_i2s_reset(SPI2);
|
||||
|
||||
/* dual line unidirectional simplex receive-only mode */
|
||||
spi_init_struct.transmission_mode = SPI_TRANSMIT_SIMPLEX_RX;
|
||||
spi_init_struct.master_slave_mode =SPI_MODE_SLAVE;
|
||||
spi_init_struct.mclk_freq_division = SPI_MCLK_DIV_8;
|
||||
spi_init_struct.first_bit_transmission = SPI_FIRST_BIT_MSB;
|
||||
spi_init_struct.frame_bit_num = SPI_FRAME_16BIT;
|
||||
spi_init_struct.clock_polarity = SPI_CLOCK_POLARITY_LOW;
|
||||
spi_init_struct.clock_phase = SPI_CLOCK_PHASE_2EDGE;
|
||||
spi_init_struct.cs_mode_selection = SPI_CS_HARDWARE_MODE;
|
||||
spi_init(SPI2, &spi_init_struct);
|
||||
|
||||
spi_enable(SPI2, TRUE);
|
||||
spi_enable(SPI1, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief gpio configuration.
|
||||
* @param none
|
||||
* @param spi_i2s_mode:select spi or i2s to be use
|
||||
* - 0 (spi mode)
|
||||
* - 1 (i2s mode)
|
||||
* @retval none
|
||||
*/
|
||||
static void gpio_config(void)
|
||||
static void gpio_config(uint16_t spi_i2s_mode)
|
||||
{
|
||||
gpio_init_type gpio_initstructure;
|
||||
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
|
||||
crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
|
||||
gpio_pin_remap_config(SWJTAG_GMUX_010, TRUE);
|
||||
gpio_pin_remap_config(SPI1_MUX_01, TRUE);
|
||||
|
||||
/* master ws pin */
|
||||
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
/* master ws/cs pin */
|
||||
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_4;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_15;
|
||||
if(spi_i2s_mode == 0)
|
||||
{
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_OUTPUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
}
|
||||
gpio_init(GPIOA, &gpio_initstructure);
|
||||
if(spi_i2s_mode == 0)
|
||||
{
|
||||
/* non communication time: master pull up CS pin release slave */
|
||||
SPI_MASTER_CS_HIGH;
|
||||
}
|
||||
|
||||
/* master ck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_5;
|
||||
gpio_init(GPIOA, &gpio_initstructure);
|
||||
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_3;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* master sd pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_7;
|
||||
gpio_init(GPIOA, &gpio_initstructure);
|
||||
|
||||
/* master mck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_0;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_5;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave ws pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_12;
|
||||
gpio_initstructure.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_12;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave ck pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_13;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_13;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
|
||||
/* slave sd pin */
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_DOWN;
|
||||
gpio_initstructure.gpio_mode = GPIO_MODE_MUX;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_15;
|
||||
gpio_initstructure.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_initstructure.gpio_pins = GPIO_PINS_15;
|
||||
gpio_init(GPIOB, &gpio_initstructure);
|
||||
}
|
||||
|
||||
@@ -203,53 +233,97 @@ int main(void)
|
||||
__IO uint32_t index = 0;
|
||||
system_clock_config();
|
||||
at32_board_init();
|
||||
at32_led_off(LED2);
|
||||
at32_led_off(LED3);
|
||||
at32_led_off(LED4);
|
||||
gpio_config();
|
||||
at32_led_on(LED4);
|
||||
|
||||
/* first: i2s communication */
|
||||
gpio_config(1);
|
||||
i2s_config(I2S_MODE_MASTER_TX, I2S_MODE_SLAVE_RX);
|
||||
i2s_enable(SPI2, TRUE);
|
||||
i2s_enable(SPI1, TRUE);
|
||||
while(rx_index < 32)
|
||||
{
|
||||
/* i2s transmit data fill */
|
||||
while(spi_i2s_flag_get(SPI1, SPI_I2S_TDBE_FLAG) == RESET);
|
||||
spi_i2s_data_transmit(SPI1, i2s1_buffer_tx[tx_index++]);
|
||||
|
||||
/* i2s receive data get */
|
||||
while(spi_i2s_flag_get(SPI2, SPI_I2S_RDBF_FLAG) == RESET);
|
||||
i2s2_buffer_rx[rx_index++] = spi_i2s_data_receive(SPI2);
|
||||
}
|
||||
|
||||
/* wait master and slave idle when communication end */
|
||||
while(spi_i2s_flag_get(SPI1, SPI_I2S_BF_FLAG) != RESET);
|
||||
while(spi_i2s_flag_get(SPI2, SPI_I2S_BF_FLAG) != RESET);
|
||||
|
||||
/* test result:the data check */
|
||||
transfer_status1 = buffer_compare(i2s2_buffer_rx, i2s1_buffer_tx, 32);
|
||||
|
||||
/* receive buffer clear */
|
||||
tx_index = 0;
|
||||
rx_index = 0;
|
||||
for(index = 0; index < 32; index++)
|
||||
{
|
||||
i2s2_buffer_rx[index] = 0;
|
||||
}
|
||||
|
||||
/* second: spi communication */
|
||||
gpio_config(0);
|
||||
spi_config();
|
||||
|
||||
/* start communication: master pull down CS pin select slave */
|
||||
SPI_MASTER_CS_LOW;
|
||||
|
||||
while(rx_index < 32)
|
||||
{
|
||||
/* spi transmit data fill */
|
||||
while(spi_i2s_flag_get(SPI1, SPI_I2S_TDBE_FLAG) == RESET);
|
||||
spi_i2s_data_transmit(SPI1, SPI1_buffer_tx[tx_index++]);
|
||||
spi_i2s_data_transmit(SPI1, spi1_buffer_tx[tx_index++]);
|
||||
|
||||
/* spi receive data get */
|
||||
while(spi_i2s_flag_get(SPI2, SPI_I2S_RDBF_FLAG) == RESET);
|
||||
spi2_buffer_rx[rx_index++] = spi_i2s_data_receive(SPI2);
|
||||
}
|
||||
|
||||
/* wait master and slave idle when communication end */
|
||||
while(spi_i2s_flag_get(SPI1, SPI_I2S_BF_FLAG) != RESET);
|
||||
while(spi_i2s_flag_get(SPI2, SPI_I2S_BF_FLAG) != RESET);
|
||||
|
||||
/* end communication: master pull up CS pin release slave */
|
||||
SPI_MASTER_CS_HIGH;
|
||||
|
||||
/* test result:the data check */
|
||||
transfer_status2 = buffer_compare(spi2_buffer_rx, SPI1_buffer_tx, 32);
|
||||
transfer_status2 = buffer_compare(spi2_buffer_rx, spi1_buffer_tx, 32);
|
||||
|
||||
for(index = 0; index < 32; index++) i2s2_buffer_rx[index] = 0;
|
||||
/* receive buffer clear */
|
||||
tx_index = 0;
|
||||
rx_index = 0;
|
||||
for(index = 0; index < 32; index++)
|
||||
{
|
||||
i2s2_buffer_rx[index] = 0;
|
||||
}
|
||||
|
||||
/* third: i2s communication */
|
||||
gpio_config(1);
|
||||
i2s_config(I2S_MODE_SLAVE_TX, I2S_MODE_MASTER_RX);
|
||||
|
||||
/* when slave transmission mode,the slave trans data need fill in advance */
|
||||
while(spi_i2s_flag_get(SPI1, SPI_I2S_TDBE_FLAG) == RESET);
|
||||
spi_i2s_data_transmit(SPI1, i2s1_buffer_tx[tx_index++]);
|
||||
|
||||
i2s_enable(SPI1, TRUE);
|
||||
i2s_enable(SPI2, TRUE);
|
||||
while(rx_index < 32)
|
||||
{
|
||||
/* i2s receive data get */
|
||||
while(spi_i2s_flag_get(SPI2, SPI_I2S_RDBF_FLAG) == RESET);
|
||||
i2s2_buffer_rx[rx_index++] = spi_i2s_data_receive(SPI2);
|
||||
|
||||
/* i2s transmit data fill */
|
||||
while(spi_i2s_flag_get(SPI1, SPI_I2S_TDBE_FLAG) == RESET);
|
||||
spi_i2s_data_transmit(SPI1, i2s1_buffer_tx[tx_index++]);
|
||||
}
|
||||
|
||||
/* master half duplex receiving mode,the busy flag isnot usefull */
|
||||
|
||||
/* test result:the data check */
|
||||
transfer_status3 = buffer_compare(i2s2_buffer_rx, i2s1_buffer_tx, 32);
|
||||
@@ -261,7 +335,7 @@ int main(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
at32_led_off(LED2);
|
||||
at32_led_on(LED3);
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user