cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L031 reading 5 digital Inputs work fine, but doing the same with 10 inputs fail.

Hugo Balette
Associate II
Posted on November 16, 2017 at 11:32

Hi !

I'm working on a STM32L031 project, and I need to read 10 digital 0V-3v3 Inputs.

Everything works fine if i'm reading 5 inputs (PA3, PA4, PA5, PA6, PA7). It is also working if I'm reading 5 other inputs (PB3, PB4, PB5, PB6, PB7).

But as soon as I plug both PA3, PA4, PA5, PA6, PA7 and PB3, PB4, PB5, PB6, PB7, it stops working.

I checked using a voltmetre in the 10 inputs config, and 4 inputs don't rise to 3v3, but only 1V.

So It only reads 3 inputs of (PA3, PA4, PA5, PA6, PA7) and 3 inputs of (PB3, PB4, PB5, PB6, PB7).

Would it be a problem of current sinking ? or just a wrong software configuration ?

I tried configuring inputs with and without pull down.

I checked GND is common to every inputs.

Any ideas ?

thanks for your time.

Hugo

#current-sink #digital-input #stm32l0 #3v3
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on November 16, 2017 at 12:00

If you are using EXTI, you can only choose one pin per source: PB3 xor PA3, PB4 xor PA4.

If you want 10 pins, you shall use Px0 to Px9, some group of pins will share the same interrupt vector.

View solution in original post

10 REPLIES 10
AvaTar
Lead
Posted on November 16, 2017 at 11:39

Instead of guessing, it would be better if you presented at least the init code for those ports.

I guess you missed something, perhaps enabling port B.

Hugo Balette
Associate II
Posted on November 16, 2017 at 11:45

Ok AvaTar, thanks for your quick response.

Here is my init code :

static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pins : Sensor_1A_Pin Sensor_2A_Pin Sensor_3A_Pin Sensor_4A_Pin Sensor_5A_Pin */ GPIO_InitStruct.Pin = Sensor_1A_Pin|Sensor_2A_Pin|Sensor_3A_Pin|Sensor_4A_Pin |Sensor_5A_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /*Configure GPIO pins : Sensor_5B_Pin Sensor_4B_Pin Sensor_3B_Pin Sensor_2B_Pin Sensor_1B_Pin */ GPIO_InitStruct.Pin = Sensor_5B_Pin|Sensor_4B_Pin|Sensor_3B_Pin|Sensor_2B_Pin |Sensor_1B_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); }

I may have forget to precise something.

When I plug all of the 10 inputs, it don't work, but as soon as I unplug 5 of the 10 inputs, is works fine.

S.Ma
Principal
Posted on November 16, 2017 at 11:54

Where these pins are connected to? If they are floating, the voltage will be random (it's like GPIOs are 'antennas').

To prevent this, you can activate a weak pull-up on each pin so that when left unconnected, you will read a 1.

More fun: If you pull-up then pull-down (with few usec delay), you can guess the pin is left unconnected...

Posted on November 16, 2017 at 11:57

These pins are connected to a pulled-down signal.

The signal is rising to 3V3 when I get an event.

I already tried to enable pull-down during initialization, but it is the same problem. :\

Thanks for your help !

Posted on November 16, 2017 at 12:00

If you are using EXTI, you can only choose one pin per source: PB3 xor PA3, PB4 xor PA4.

If you want 10 pins, you shall use Px0 to Px9, some group of pins will share the same interrupt vector.

Posted on November 16, 2017 at 12:03

Thanks

KIC8462852 EPIC204278916

for your answer.

I'm not using EXTI, or interruptions for the moment, but I'll try to use the same GPIO PORT.

Thanks !

Posted on November 16, 2017 at 12:33

Thanks for your advise KIC8462852 EPIC204278916

After using one single GPIO PORT, it is now working fine.

I can't explain why because I wasn't using interrupts, but using only PORTA works fine !

Thanks !

Posted on November 16, 2017 at 12:44

After using one single GPIO PORT, it is now working fine.

I can't explain why because I wasn't using interrupts, but using only PORTA works fine !

Most probably because your initialization of port B was not correct.

175662CGIL6