CH32V307VCT6 SPI1 Remap not working - Page 1
Forum section: electronics / general

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: June 11, 2023, 01:47:32 pm
content: Hi,I want to use SPI1 in remap mode for CH32V307VCT6 , the normal examples just works, But I have modified the code to use remap, The SPI does not work in this mode and SPI_I2S_FLAG_TXE flag just would not get to 1, so I can not send the next byte,Here is what I have done,Code:void SPI_FullDuplex_Init(void){GPIO_InitTypeDef GPIO_InitStructure={0};SPI_InitTypeDef SPI_InitStructure={0};RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB | RCC_APB2Periph_SPI1 | RCC_APB2Periph_AFIO, ENABLE );GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;GPIO_Init( GPIOA, &GPIO_InitStructure );GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init( GPIOB, &GPIO_InitStructure );GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init( GPIOB, &GPIO_InitStructure );GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init( GPIOB, &GPIO_InitStructure );SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;SPI_InitStructure.SPI_CRCPolynomial = 7;SPI_Init( SPI1, &SPI_InitStructure );SPI_SSOutputCmd( SPI1, DISABLE );SPI_Cmd( SPI1, ENABLE );}int main(void){SPI_FullDuplex_Init();while(1){for(int i=0;i<18;){if( SPI_I2S_GetFlagStatus( SPI1, SPI_I2S_FLAG_TXE ) != RESET ){SPI_I2S_SendData( SPI1, TxData );i++;}if( SPI_I2S_GetFlagStatus( SPI1, SPI_I2S_FLAG_RXNE ) != RESET ){RxData = SPI_I2S_ReceiveData( SPI1 );}}}}And this is just the original code that's working fineCode:void SPI_FullDuplex_Init(void){GPIO_InitTypeDef GPIO_InitStructure={0};SPI_InitTypeDef SPI_InitStructure={0};RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB | RCC_APB2Periph_SPI1 | RCC_APB2Periph_AFIO, ENABLE );GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;GPIO_Init( GPIOA, &GPIO_InitStructure );GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init( GPIOA, &GPIO_InitStructure );GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init( GPIOA, &GPIO_InitStructure );GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init( GPIOA, &GPIO_InitStructure );SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;SPI_InitStructure.SPI_CRCPolynomial = 7;SPI_Init( SPI1, &SPI_InitStructure );SPI_SSOutputCmd( SPI1, DISABLE );SPI_Cmd( SPI1, ENABLE );}

author: bidrohini1
author_rank: Contributor
timestamp: June 13, 2023, 11:07:17 am
content: Sorry I am not experienced in using CH32V307VCT6. However, you can post this snippet to the Armbian forum.