cancel
Showing results for 
Search instead for 
Did you mean: 

Inputs GPIO

edgarmedina20
Associate II
Posted on May 09, 2014 at 22:09

Hello everybody.

I want to solve a read problem in a special hardware, the configuration of each pin is input:

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_Init(GPIOC, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_6 | GPIO_Pin_10;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOC, &GPIO_InitStructure);

there many pins work...

my problem is in the next code (this is a function in my library):

unsigned int ReadData(void)

{

   unsigned char nop=eco;//eco=5, is a delay.

   unsigned int data = 0;

   unsigned char count=0;

   for(count=0; count<12; count++)

   {

      data <<= 1;

      GPIO_SetBits(GPIOC, GPIO_Pin_10);               

      while(nop!=0){nop--;}

       nop=eco;

      GPIO_ResetBits(GPIOC, GPIO_Pin_10);

      while(nop!=0){nop--;}

      nop=eco;

      if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_8));

{data++;}

   }

   return(data);

}

when I read the value in data, only I read 0xFFF (12 bits)  in all cases, but I see signals for example 0x34F or 0x584 many combinations and I saw a good synchronization with the clock

using a analyzer logic. maybe is the configuration of the inputs but I 'm not sure.

thank you in advance.

#input-configuration
6 REPLIES 6
Posted on May 09, 2014 at 22:20

Make nop volatile

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
edgarmedina20
Associate II
Posted on May 09, 2014 at 22:37

Thank you for your speed answer, but sorry, How is ''Make nop volatile''?

do I make it in the variables of the function ReadData? because the variable ''nop'' is only a delay but it isn't important, the most important value is Data but when I return this, the value is all ones (0xFFF).

thank you so much.

Posted on May 09, 2014 at 22:51

 volatile unsigned char nop=eco;//eco=5, is a delay.

This way the compiler won't optimize it away.

When does the data line come valid with respect to the pulse sent out?

There are pipeline and synchronization delays with respect to reading bits back.

Are you sure you are looking at the right bit, can you ever read the pin low?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
edgarmedina20
Associate II
Posted on May 09, 2014 at 23:29

Thank you for the information about the volatile in the variable ''nop''.

mm.. I'm reading the registers 0x90 and 0xD0 on the XPT2046 and the communication protocol like this.

http://www.sunrom.com/media/content/557/images/signals.gif

SPI communication.

When does the data line come valid with respect to the pulse sent out?

A: is when I write the 0x90 and dthe 0xD0 in another stage of my code, but I look the shipping of the data and it's correct and have a good synchronization .

Are you sure you are looking at the right bit, can you ever read the pin low?

A:yes, I'm sure :\  the code emule the SPI through software for eliminate error of configurations or bugs. I looked different values between 0x010 and 0xFE0 and never is the maximun value(0xFFF) at least I never looked this (because the limitation of the hardware the resistive panel).

there is a correct synchronization or so it seems.
edgarmedina20
Associate II
Posted on May 09, 2014 at 23:29

I changed the pin, the pin PC8 was changed by PA1 and I have the same result, I think the problem is the configuration when I use the instruction ''GPIO_ReadInputDataBit'' only read '1'.

:(
Posted on May 10, 2014 at 03:13

Get rid of the semi-colon at the end of the 'if' line

if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_8)); // <-- DON'T PUT THAT SEMICOLON HERE
 {data++;}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..