Jump to content

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


Phatline
 Share

Recommended Posts

 

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?

Edited by Phatline
Link to comment
Share on other sites

  • 2 weeks later...

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...

Edited by Phatline
Link to comment
Share on other sites

also if i follow this tip:

Quote

 

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

Edited by Phatline
Link to comment
Share on other sites

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

Edited by Phatline
Link to comment
Share on other sites

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){}
Edited by Antichambre
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

i just read the documentation; 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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...