Page 1 of 2

trubles with buttons STM32L-DISCOVERY

Posted: Sat Jun 23, 2012 9:46 pm
by skmskm
I using STM32L-DISCOVERY board
version is 2.4.1.
i am alerady usin 5 pwm's.
I don't know why but i canot set more buttons than one build in on board(one off maine butons works becose its conested to port off build in one).
All rest dont work(12).
buttons are to control tank robot.

Code: Select all

//piny z panelu sterowania
   // prawa
   // PC0- szybko tyl
   // PC1- tyl
   // PC2- przud
   // PC3- szybko przud
   // PA0- zewnetrzny a
   // PA1- wewnetrzny a
   // lewa
   // PA2- szybko tyl
   // PA3- tyl
   // PA4- przud
   // PA5- szybko przud
   // PB2- zewnetrzny b
   // PB10- wewnetrzny b
  while (TRUE) {
               //prawa gonsienica
               if (palReadPad(GPIOC, 0) == PAL_HIGH){
                  buff.gprawa = 1100;
               }else if (palReadPad(GPIOC, 1) == PAL_HIGH){
                  buff.gprawa = 800;
               }else if (palReadPad(GPIOC, 2) == PAL_HIGH){
                  buff.gprawa = 600;
               }else if (palReadPad(GPIOC, 3) == PAL_HIGH){
                  buff.gprawa = 300;
               }else{
                  buff.gprawa = 700;
               }
               //lewa gonsienica
               if (palReadPad(GPIOA, 2) == PAL_HIGH)
               {
                  buff.glewa = 1100;
               }else
               if (palReadPad(GPIOA, 3) == PAL_HIGH)
               {
                  buff.glewa = 800;
               }
               else
               if (palReadPad(GPIOA, 4) == PAL_HIGH)
               {
                  buff.glewa = 600;
               }
               else
               if (palReadPad(GPIOA, 5) == PAL_HIGH)
               {
                  buff.glewa = 300;
               }else{
                  buff.glewa = 700;
               }
               //szczeki
               if (palReadPad(GPIOA, 0) == PAL_HIGH)//this one works
               {
                  buff.lewa -= 10;
                  buff.prawa += 10;
               }else if (palReadPad(GPIOA, 1) == PAL_HIGH)
               {
                  buff.lewa += 10;
                  buff.prawa -= 10;
               }
               //kat
               if (palReadPad(GPIOB, 2) == PAL_HIGH)
               {
                  buff.kat -= 2;
               }
               else
               if (palReadPad(GPIOB, 10) == PAL_HIGH)
               {
                  buff.kat += 2;
               }
               chSysLockFromIsr();
               pwmEnableChannelI(&PWMD4, 2, PWM_PERCENTAGE_TO_WIDTH(&PWMD4, buff.glewa));//PB8 // lewa
               pwmEnableChannelI(&PWMD3, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, buff.gprawa));//PC6 // prawa
               pwmEnableChannelI(&PWMD3, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, buff.kat));//pc7 // kat
               
               pwmEnableChannelI(&PWMD3, 2, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, buff.lewa));//PC8 // lewa_szceka
               
               pwmEnableChannelI(&PWMD3, 3, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, buff.prawa));//PC9 //prawa_szczeka
               chSysUnlockFromIsr();
               chThdSleepMilliseconds(40);
      }
  }

i got something wrong mebe here?

Code: Select all

#define VAL_GPIOA_MODER             (PIN_MODE_INPUT(GPIOA_BUTTON) |         \
                                     PIN_MODE_INPUT(1) |                    \
                                     PIN_MODE_INPUT(2) |                    \
                                     PIN_MODE_INPUT(3) |                    \
                                     PIN_MODE_INPUT(4) |                    \
                                     PIN_MODE_INPUT(5) |                    \
                                     PIN_MODE_INPUT(6) |                    \
                                     PIN_MODE_INPUT(7) |                    \
                                     PIN_MODE_INPUT(8) |                    \
                                     PIN_MODE_INPUT(9) |                    \
                                     PIN_MODE_INPUT(10) |                   \
                                     PIN_MODE_INPUT(11) |                   \
                                     PIN_MODE_INPUT(12) |                   \
                                     PIN_MODE_ALTERNATE(13) |               \
                                     PIN_MODE_ALTERNATE(14) |               \
                                     PIN_MODE_ALTERNATE(15))
#define VAL_GPIOA_OTYPER            0x00000000
#define VAL_GPIOA_OSPEEDR           0xFFFFFFFF
#define VAL_GPIOA_PUPDR             (PIN_PUDR_PULLUP(GPIOA_BUTTON) |        \
                                     PIN_PUDR_PULLUP(1) |                   \
                                     PIN_PUDR_PULLUP(2) |                   \
                                     PIN_PUDR_PULLUP(3) |                   \
                                     PIN_PUDR_PULLUP(4) |                   \
                                     PIN_PUDR_PULLUP(5) |                   \
                                     PIN_PUDR_PULLUP(6) |                   \
                                     PIN_PUDR_PULLUP(7) |                   \
                                     PIN_PUDR_PULLUP(8) |                   \
                                     PIN_PUDR_PULLUP(9) |                   \
                                     PIN_PUDR_PULLUP(10) |                  \
                                     PIN_PUDR_PULLUP(11) |                  \
                                     PIN_PUDR_PULLUP(12) |                  \
                                     PIN_PUDR_FLOATING(13) |                \
                                     PIN_PUDR_FLOATING(14) |                \
                                     PIN_PUDR_FLOATING(15))
#define VAL_GPIOA_ODR               0xFFFFFFFF
#define VAL_GPIOA_AFRL              0x00000000
#define VAL_GPIOA_AFRH              0x00000000

Re: trubles with buttons STM32L-DISCOVERY

Posted: Sun Jun 24, 2012 5:49 am
by Giovanni
Hi,

Did you remove the LCD from the board? those pins are normally connected to the LCD. It is possible this is your problem because I don't see anything obviously wrong in the code.

Giovanni

Re: trubles with buttons STM32L-DISCOVERY

Posted: Sun Jun 24, 2012 11:00 am
by skmskm
I removed LCD that don't help

Re: trubles with buttons STM32L-DISCOVERY

Posted: Sun Jun 24, 2012 11:05 am
by Giovanni
How those buttons are connected? do you have external pull-up/pull-down resistors?

Also, you have lots of "else if" id one of those conditions is true the following ones are not executed, if the button is not pressed those pins will read as 1 because internal pull-ups.

Giovanni

Re: trubles with buttons STM32L-DISCOVERY

Posted: Sun Jun 24, 2012 11:09 am
by skmskm
i conected:
VDD->320ohm->buttons->pins is this ok?

Re: trubles with buttons STM32L-DISCOVERY

Posted: Sun Jun 24, 2012 11:22 am
by Giovanni
No, it reads always like 1 because internal pull up resistors.

Connect a 10K resistor between VDD and pin, then connect the button between pin and GND. You may also disable internal pull-ups because you have external ones.

The pin will read as zero when the button is pressed else 1.

Giovanni

Re: trubles with buttons STM32L-DISCOVERY

Posted: Sun Jun 24, 2012 11:49 am
by skmskm
I am stating to think bout buing an plc...
still not working.
its tigers alweys both:
if (palReadPad(GPIOC, 0) == PAL_LOW)
if (palReadPad(GPIOC, 0) == PAL_HIGH)

Re: trubles with buttons STM32L-DISCOVERY

Posted: Sun Jun 24, 2012 11:56 am
by Giovanni
I can only suggest to replicate exactly the same circuit of the Discovery on-board button for each button you need. The schematic is on the board manual.

Giovanni

Re: trubles with buttons STM32L-DISCOVERY

Posted: Sun Jun 24, 2012 12:14 pm
by skmskm
I miss one part for this C30 - 100uF without it not working

Re: trubles with buttons STM32L-DISCOVERY

Posted: Sun Jun 24, 2012 1:20 pm
by Giovanni
It would work even without that 100nF (not uF) capacitor, it is just for debouncing.

Giovanni