-1

How to use AFIO14 for pin multiplexing in stm32l151 chip.

The reason for asking this question is that I want to use the input capture function of the timer, but the channel pin of the timer is occupied by other devices. Is there a way to use PC13 as the input capture pin of the timer.

enter image description here enter image description here

Can you provide an example code written in C language.

Kuno
  • 1
  • 1

1 Answers1

0

The 'L1xx family has a quite peculiar switch matrix, which is unique amongst the STM32.

So, the procedure is, that you set PC13 to Alternative Function and set it's AF to 14.

Then you set individual fields in RI_ICR register so that PC13 is routed to required timer. Read Input capture routing subchapter of System configuration controller (SYSCFG) and routing interface (RI) chapter in RM0038.

I don't have an 'L15x to try, but generally, this code should accomplish this (assuming you want to connect PC13 to TIM2_CH2):

GPIOC->AFR[1] = GPIOC->AFR[1] & ~(0b1111 << (4 * (13 - 8)))) | (14 << (4 * (13 - 8)));  // set AF of PC13 to 14
GPIOC->MODER = (GPIOC->MODER & ~(0b11 << (2 * 13))) | (0b10 << (2 * 13));  // set PC13 as AF
RI->ICR = (0b0010 << 18) // set IC2 field, so that Input Capture 2 is used
  | (0b01 << 16)  // set TIM field to TIM2
  | (0b0111 << (1 * 4))  // set IC2IOS to select PC13
;

JW

PS. Note that 'L1xx are NRND, even if 8.5 years of ST's 10 year commitment still remains.

wek
  • 137
  • 3