/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Bit-banging problem...

Username:     
Password:     
             

Forum

# 1   2009-09-02 11:58:04 Bit-banging problem...

logictechs
Member
Registered: 2009-05-07
Posts: 68

Bit-banging problem...

Hi,

I've been trying to use the following code to send a byte out of pin A.3(RX pin on the external connector port):

/* Enable GPIOx clock */
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
   GPIO_InitTypeDef GPIO_InitStructure;
/* Configure Rx as output */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOA, &GPIO_InitStructure);   


void delay1 (int time)
{
int i;
    time *= 10;
    for(i = 0; i < time; i++)
        asm volatile ("nop");
}

void write_byte(unsigned char val)
{
u8 i;
u8 temp;

for(i=0;i<8;i++)
{
temp = val >> i;
temp &=0x01;
if (temp)
{
GPIO_WriteBit(GPIOA, GPIO_Pin_3, Bit_RESET);
delay1(1);
GPIO_WriteBit(GPIOA, GPIO_Pin_3, Bit_SET);
delay1(16);
}
else
{
GPIO_WriteBit(GPIOA, GPIO_Pin_3, Bit_RESET);
delay1(15);
GPIO_WriteBit(GPIOA, GPIO_Pin_3, Bit_SET);
}
}
delay1(65);
GPIO_WriteBit(GPIOA, GPIO_Pin_3, Bit_SET);
}

When I send a byte to the write_byte function I get much more toggles than expected.  I've disabled timer2.  Has anyone seen this or see something wrong with my code?  Thanks!

Offline

 

Board footer