MIOS32_BOARD_Jx_PinGet (x) returns 0 (when set 2 ANalog)

 

i cant get it working, tryd for ours (meanwhile for days…) i want to read the J5 Pins periodicaly (want to read a IR-Sensor)

 

that should do the job:

void APP\_Init(void){ MIOS32\_BOARD\_J5\_PinInit(4, MIOS32\_BOARD\_PIN\_MODE\_ANALOG); } void APP\_Tick(void){ s16 state = MIOS32\_BOARD\_J5\_PinGet (4); MIOS32\_MIDI\_SendDebugMessage("val: %d ", state ) ;}

MIOS-Monitor print: val: 0.

 

Its No Hardware Issue, since:

When config the J5 Pins as DIN or DOUT , i can get and set them with no problems

&&

when using J5A/B in combination with  APP_AIN,  i get “normal” values (>0!)…

… also i all different variations in mios_config like…:

#define MIOS32\_AIN\_CHANNEL\_MASK 0x00ff #define MIOS32\_AIN\_CHANNEL\_MASK 0x0000 #define MIOS32\_DONT\_SERVICE\_AIN 1 #define MIOS32\_DONT\_SERVICE\_AIN 0 #define MIOS32\_DONT\_USE\_AIN 1 #define MIOS32\_DONT\_USE\_AIN 0

also if i try to set the Pin Value (joke it)

 MIOS32\_BOARD\_J5\_PinSet (4, 3);

and then make a PinGet, i become 0 (

 

&& J10 do the same when set to PIN_MODE_ANALOG!!!

 

bug?

I cant find out the issue…

i am looking into mios32_ain.c and mios32_board.c

and when i break it down to the J5 Part, a code for initialze and get the J5 Pins would be like this (debuging give me a 0)

void APP\_MIDI\_Tick(void){ // Test J5 Pin every second static int secflag = 0; secflag++; if( secflag \> 1000) { secflag = 0; // this table maps ADC channels to J5.Ax pins typedef struct { u8 chn; GPIO\_TypeDef \*port; u16 pin\_mask; } adc\_chn\_map\_t; static const adc\_chn\_map\_t adc\_chn\_map[8] = { { ADC\_Channel\_11, GPIOC, GPIO\_Pin\_1 }, // J5A.A0 { ADC\_Channel\_12, GPIOC, GPIO\_Pin\_2 }, // J5A.A1 { ADC\_Channel\_1, GPIOA, GPIO\_Pin\_1 }, // J5A.A2 { ADC\_Channel\_4, GPIOA, GPIO\_Pin\_4 }, // J5A.A3 { ADC\_Channel\_14, GPIOC, GPIO\_Pin\_4 }, // J5B.A4 { ADC\_Channel\_15, GPIOC, GPIO\_Pin\_5 }, // J5B.A5 { ADC\_Channel\_8, GPIOB, GPIO\_Pin\_0 }, // J5B.A6 { ADC\_Channel\_9, GPIOB, GPIO\_Pin\_1 }, // J5B.A7 }; // set analog pins GPIO\_InitTypeDef GPIO\_InitStructure; GPIO\_StructInit(&GPIO\_InitStructure); GPIO\_InitStructure.GPIO\_Mode = GPIO\_Mode\_AN; GPIO\_InitStructure.GPIO\_PuPd = GPIO\_PuPd\_NOPULL; int i;for(i=0; i\<8; ++i) { GPIO\_InitStructure.GPIO\_Pin = adc\_chn\_map[i].pin\_mask; GPIO\_Init(adc\_chn\_map[i].port, &GPIO\_InitStructure); } MIOS32\_MIDI\_SendDebugMessage("J5A Pin0: %d", MIOS32\_SYS\_STM\_PINGET(GPIOC, GPIO\_Pin\_1) ) ; MIOS32\_MIDI\_SendDebugMessage("J5B Pin0: %d", MIOS32\_SYS\_STM\_PINGET(GPIOC, GPIO\_Pin\_4) ) ; }

 

if i break it down to get J5A Pin 0 and J5B Pin0 the code should look like this? (this again debugging return me 0 and 0!

void APP\_MIDI\_Tick(void){ // Test J5 Pin every second static int secflag = 0; secflag++; if( secflag \> 1000) { secflag = 0; // set analog pins GPIO\_InitTypeDef GPIO\_InitStructure; GPIO\_StructInit(&GPIO\_InitStructure); GPIO\_InitStructure.GPIO\_Mode = GPIO\_Mode\_AN; GPIO\_InitStructure.GPIO\_PuPd = GPIO\_PuPd\_NOPULL; // PIN J5A 0 GPIO\_InitStructure.GPIO\_Pin = GPIO\_Pin\_1; GPIO\_Init(GPIOC, &GPIO\_InitStructure); // PIN J5B 0 GPIO\_InitStructure.GPIO\_Pin = GPIO\_Pin\_4; GPIO\_Init(GPIOC, &GPIO\_InitStructure); MIOS32\_MIDI\_SendDebugMessage("J5A Pin0: %d", MIOS32\_SYS\_STM\_PINGET(GPIOC, GPIO\_Pin\_1) ) ; MIOS32\_MIDI\_SendDebugMessage("J5B Pin0: %d", MIOS32\_SYS\_STM\_PINGET(GPIOC, GPIO\_Pin\_4) ) ; }

 

 

And i cant find:" MIOS32_SYS_STM_PINGET()"?  >>> it isnt: http://www.midibox.org/mios32/manual/_s_t_m32_f4xx_2mios32__sys_8c.html

because there isnt a “STM_PINGET” ? or is it?

  … on this point my research stops, since i cant find it

just try to find out where the problem is, since the simple and userfriendly “MIOS32_BOARD_J5_PinGet (4);” wont work…

also if i follow this tip:

Quote

http://discourse.midibox.org/t/topic/20381

 

and make a code like this:

void APP\_MIDI\_Tick(void){ // Test J5 Pin every second static int secflag = 0;//initalize secflag++;//ms counter if( secflag \> 1000) { secflag = 0;//reset counter static int init = 1; if (init == 1) { init = 0;// run only @ first time // Init J5A0 and J5B Pin 0 as Analog Inputs GPIO\_InitTypeDef GPIO\_InitStructure; GPIO\_StructInit(&GPIO\_InitStructure); GPIO\_InitStructure.GPIO\_Speed = GPIO\_Speed\_50MHz; GPIO\_InitStructure.GPIO\_Pin = GPIO\_Pin\_1; // J5A 0 GPIO\_InitStructure.GPIO\_Mode = GPIO\_Mode\_AN; GPIO\_InitStructure.GPIO\_PuPd = GPIO\_PuPd\_NOPULL; GPIO\_Init(GPIOC, &GPIO\_InitStructure); GPIO\_StructInit(&GPIO\_InitStructure); GPIO\_InitStructure.GPIO\_Speed = GPIO\_Speed\_50MHz; GPIO\_InitStructure.GPIO\_Pin = GPIO\_Pin\_4; // J5B 0 GPIO\_InitStructure.GPIO\_Mode = GPIO\_Mode\_AN; GPIO\_InitStructure.GPIO\_PuPd = GPIO\_PuPd\_NOPULL; GPIO\_Init(GPIOC, &GPIO\_InitStructure); } static u8 value = 0; // initalize variable // Get Pin State J5A 0 value = MIOS32\_SYS\_STM\_PINGET(GPIOC, GPIO\_Pin\_1); MIOS32\_MIDI\_SendDebugMessage("J5A Pin0: %d", value ); // Get Pin State J5B 0 value = (u8)MIOS32\_SYS\_STM\_PINGET(GPIOC, GPIO\_Pin\_4); MIOS32\_MIDI\_SendDebugMessage("J5B Pin0: %d", value ); }

 

and or not add this lines in mios32_config.h: (it doesnt matter)

#define MIOS32\_DONT\_SERVICE\_AIN 1 #define MIOS32\_DONT\_USE\_AIN 1

return me a debugging messages of 0 and 0

Can anyone confirm that this simple code Work/not Work?

j5pinget.zipj5pinget.zipj5pinget.zip

anyone with a STM32F4 can test this… the code should not hang your device since it is only call every second.

 

thx 4 help.

#include \<mios32.h\> #include \<FreeRTOS.h\> #include \<task.h\> #include "app.h" // Init J5A+B Pin 0 as ANalog Input void APP\_Init(void){ MIOS32\_BOARD\_J5\_PinInit(0, MIOS32\_BOARD\_PIN\_MODE\_ANALOG); MIOS32\_BOARD\_J5\_PinInit(4, MIOS32\_BOARD\_PIN\_MODE\_ANALOG); } void APP\_Background(void) {} // Get J5A-B Pin 0 every second void APP\_Tick(void){ static int seccount = 0;// init counter seccount++; if (seccount \> 1000) { seccount = 0;// reset counter static s16 state = 0; // Get J5A0 state = MIOS32\_BOARD\_J5\_PinGet (0); MIOS32\_MIDI\_SendDebugMessage("J5A-Pin0: %d ", state ) ; // Get J5b0 state = MIOS32\_BOARD\_J5\_PinGet (4); MIOS32\_MIDI\_SendDebugMessage("J5B-Pin0: %d ", state ) ; } } void APP\_MIDI\_NotifyPackage(mios32\_midi\_port\_t port, mios32\_midi\_package\_t midi\_package){} void APP\_SRIO\_ServicePrepare(void){} void APP\_SRIO\_ServiceFinish(void){} void APP\_DIN\_NotifyToggle(u32 pin, u32 pin\_value) {} void APP\_ENC\_NotifyChange(u32 encoder, s32 incrementer){}

 

j5pinget.zip

Hi,

Your if condition is never true cause you put initialization to 0 and increment of seccount in the same hook. APP_Tick is called by TASK_Hooks every ms.

#include \<mios32.h\> #include \<FreeRTOS.h\> #include \<task.h\> #include "app.h" static int seccount = 0; // Init J5A+B Pin 0 as ANalog Input void APP\_Init(void){ MIOS32\_BOARD\_J5\_PinInit(0, MIOS32\_BOARD\_PIN\_MODE\_ANALOG); MIOS32\_BOARD\_J5\_PinInit(4, MIOS32\_BOARD\_PIN\_MODE\_ANALOG); } void APP\_Background(void) {} // Get J5A-B Pin 0 every second void APP\_Tick(void){ seccount++; if (seccount \> 1000) { seccount = 0; // reset counter static s16 state = 0; // Get J5A0 state = MIOS32\_BOARD\_J5\_PinGet (0); MIOS32\_MIDI\_SendDebugMessage("J5A-Pin0: %d ", state ) ; // Get J5b0 state = MIOS32\_BOARD\_J5\_PinGet (4); MIOS32\_MIDI\_SendDebugMessage("J5B-Pin0: %d ", state ) ; } } void APP\_MIDI\_NotifyPackage(mios32\_midi\_port\_t port, mios32\_midi\_package\_t midi\_package){} void APP\_SRIO\_ServicePrepare(void){} void APP\_SRIO\_ServiceFinish(void){} void APP\_DIN\_NotifyToggle(u32 pin, u32 pin\_value) {} void APP\_ENC\_NotifyChange(u32 encoder, s32 incrementer){}

no, my code on this point is right:

the word

“static”

initialize a variable only @ first run, after that - the init-value “0” is ignored.

 

this is really handy

1 Like

Ahah sorry, I learnt something today! thanks!

Could you please try following tutorial application:

https://github.com/midibox/mios32/tree/master/apps/tutorials/005_polling_j5_pins

It shows the intended way, how to use J5 pins as inputs.

And it’s also a good test application to ensure, that the pins are (still) working.

Best Regards, Thorsten.

hi

i tested the tutorial now, and set as Digital Input- as the Tutorial is, it works. it sends midi notes when moving the potentiometers.

but when changing the initalitaion to

void APP\_Init(void) { // initialize all LEDs MIOS32\_BOARD\_LED\_Init(0xffffffff); // initialize all pins of J5A, J5B and J5C as inputs with internal Pull-Up int pin; for(pin=0; pin\<12; ++pin) MIOS32\_BOARD\_J5\_PinInit(pin, MIOS32\_BOARD\_PIN\_MODE\_ANALOG); }

and let the rest of the tutorial untouched, it doesnt send anything when moving any of the 8 potentiometers. the Analog mode doesnt work - or what do i miss here?

MIOS32_BOARD_* functions are intended for reading the pins in digital, and not in analog mode.

For Analog readouts you’ve to use the AIN driver.

See following tutorial: https://github.com/midibox/mios32/tree/master/apps/tutorials/011_ain

Best Regards, Thorsten.

i just read the documentation; [http://www.midibox.org/mios32/manual/group\_\_\_m\_i\_o\_s32\_\_\_b\_o\_a\_r\_d.html#gae4a1b2afe98fdf86a5b20216fe4c2bbd](http://www.midibox.org/mios32/manual/group m_i_o_s32 b_o_a_r_d.html#gae4a1b2afe98fdf86a5b20216fe4c2bbd)

Quote

MIOS32_BOARD_PIN_MODE_ANALOG: select analog input mode (default)

for me it seemed that it should work…

 

When using AIN-Driver,  the AINs are read in background.

can i then manually command to start a read out? (maybe in combination with “#define MIOS32_DONT_SERVICE_AIN 1”?)

 

background to this quest :

i have 4 IR Diodes, and one IR Receiver (my AIN) i have to cycle ON/OFF-the 4IR Diodes… So i have to Activate a Diode, read the state, deactivate it, then the next Diode, read the AIN State, its importend to do this in perfect timing. (in order to calculate a XYZ-Read out of my hand)

Analog pins are permanently polled by the AIN driver, this is done via DMA in background (so that the CPU isn’t loaded)

If you’ve to set pins before the next scan, then just use a AIN ServicePrepare callback.

See also following tutorial which shows how to scan a touchscreen - actually a similar handling like described for your use case: https://github.com/midibox/mios32/tree/master/apps/tutorials/022_glcd_touchpanel

Best Regards, Thorsten.

sound like a plan! thx.