Author Topic: CH32V003F4P6 I2C port pin Remapping - MounriverStudio (SOLVED)  (Read 518 times)

0 Members and 1 Guest are viewing this topic.

Offline corgonTopic starter

  • Newbie
  • Posts: 2
  • Country: cz
CH32V003F4P6 I2C port pin Remapping - MounriverStudio (SOLVED)
« on: January 29, 2024, 04:59:28 pm »
Hello, I'm new here on the forum.
I would like to ask more experienced members where I might be making a mistake.
I'm trying to remap the I2C port on CH32V003F4P6 to the PD0, PD1 pins.
I'm using the I2C port for the SSD1306 OLED display.
Unfortunately, it's not working. I am using the following config:
Code: [Select]
void IIC_Init(u32 bound, u16 address) {
GPIO_InitTypeDef GPIO_InitStructure = { 0 };
I2C_InitTypeDef I2C_InitTSturcture  = { 0 };

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE );
RCC_APB1PeriphClockCmd( RCC_APB1Periph_I2C1, ENABLE );

GPIO_PinRemapConfig (GPIO_PartialRemap_I2C1, ENABLE );  // REMAP I2c to Pins: PD0, PD1

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOD, &GPIO_InitStructure);

I2C_InitTSturcture.I2C_ClockSpeed = bound;
I2C_InitTSturcture.I2C_Mode = I2C_Mode_I2C;
I2C_InitTSturcture.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitTSturcture.I2C_OwnAddress1 = address;
I2C_InitTSturcture.I2C_Ack = I2C_Ack_Enable;
I2C_InitTSturcture.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_Init( I2C1, &I2C_InitTSturcture);

I2C_Cmd( I2C1, ENABLE);

I2C_AcknowledgeConfig( I2C1, ENABLE);
}

I think the problem might be that the PD1 pin is also the programming pin SWDIO.
I've been trying to figure it out for two days, but still without success.
Can you point me in the right direction?
Just so you know, remapping to pin PC5, PC6 is working smoothly without any problems.
Thanks, Corgon.
« Last Edit: January 30, 2024, 10:59:19 am by corgon »
 

Offline corgonTopic starter

  • Newbie
  • Posts: 2
  • Country: cz
Re: CH32V003F4P6 I2C port pin Remapping - MounriverStudio
« Reply #1 on: January 29, 2024, 06:36:34 pm »
Finally, I figured it out. Just need to disable the SWDIO port with the following command:
Code: [Select]
GPIO_PinRemapConfig (GPIO_Remap_SDI_Disable, ENABLE);
Just needed to read the Reference Manual more thoroughly. According to the RTFM  :)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf