/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / digital inputs are being displayed as the letter I

Username:     
Password:     
             

Forum
  • Index
  •  » circleOS
  •  » digital inputs are being displayed as the letter I

# 1   2010-06-03 07:16:42 digital inputs are being displayed as the letter I

unclesam88
New member
Registered: 2010-05-02
Posts: 6

digital inputs are being displayed as the letter I

Hi,

Im trying to get the primer 2 to use an external clock (pin4) as a trigger to read the digital input on a different digital input pin (pin5) . I want to display what is being read on pin5 to verify I am receiving the proper data but so far I only get the letter I with 2 dots on top of it.

//**GPIO initialization sets pin4 and pin5 as digital inputs
    GPIO_InitTypeDef  GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

unsigned int DOUT_current;
unsigned int DOUT_Data[];
char DOUT_current_str;
int L;
       
       
        for (L=0; L<8; )   
        {
            while( GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4) == 1)
            {
                DOUT_current = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5);
                DOUT_Data [L] = DOUT_current;
       
                UTIL_uint2str(DOUT_current_str,DOUT_current,1,0);
                DRAW_DisplayString(L*10,50,DOUT_current_str,1 );
           
                L++;
            }
         }

everytime the external clock goes high, I want pin5 to read and store the binary number into DOUT_current and display it on the screen. DOUT_Data[L] is for saving each input. I also left the thrid section of the for loop blank so the loop wont advance until the clock goes high. Either way im sure this code is not very good but regardless the primer2 displays I's. Probably my variable declarations are not right.

~Sam

Offline

 

# 2   2010-06-03 14:08:18 digital inputs are being displayed as the letter I

ntrf.zns
Member
From: Belgorod, Russia
Registered: 2009-11-01
Posts: 134

Re: digital inputs are being displayed as the letter I

Did you ever used C/C++ before? What you wrote is a single character variable and you need a string variable of fixed length. Length of string should be big enough to hold a number from range [0..255] (thats three) and termitation symbol (thats one more).

Code:

char DOUT_current_str; //Change this
char DOUT_current_str[4]; //To this

Thats only the begining. Your other declaration is incorrect as well. You need to either specify the fixed size or initialize variable with array of values.

Code:

unsigned int DOUT_Data[ /*put size here*/ ];

And still you have an error. Your 'while' will keep receiving the same byte all over again. Try to figure how to detect edges yourself.

PS: looks like you're trying to connect PC keyboard to primer...

Last edited by ntrf.zns (2010-06-03 14:10:07)

Offline

 

# 3   2010-06-03 14:38:14 digital inputs are being displayed as the letter I

unclesam88
New member
Registered: 2010-05-02
Posts: 6

Re: digital inputs are being displayed as the letter I

Yeah its been a while since I've taken a basic C class.

What I have been confused about is if I am trying to read a digital value, do i have to read it as binary and later convert it to decimal or is there some way to read it straight as a decimal value?

thanks for the tips

Offline

 

# 4   2010-06-03 15:44:14 digital inputs are being displayed as the letter I

ntrf.zns
Member
From: Belgorod, Russia
Registered: 2009-11-01
Posts: 134

Re: digital inputs are being displayed as the letter I

I don't understand what do you meany by "reading the decimal".

In your case you're reading bits. Which means you can easily convert bit to string using a lookup table:

Code:

const char BinaryLookupTable[2] = { "0", "1" };
...
DRAW_DisplayString(L*10, 50, BinaryLookupTable[DOUT_current], 1 ); //Usage

If you want to convert all those 8 bits into a single byte, than you need to build it in the loop. Intead of storing values into the array, use single byte variable and ADD bits to it. To get value with L'th bit set use shift operator (<<). Don't forget to clear it to zero before the loop.

Code:

if(DOUT_current != 0)
    MyData += (1 << L);

Offline

 

  • Index
  •  » circleOS
  •  » digital inputs are being displayed as the letter I

Board footer