2019-04-02 10:31 AM
STM32F722 Strange GPIO problem with Multiple CD4094(Serial to Parallel Converter)
Hi,
I am working with GPIO LED , LCD 4-bit Mode Working fine.
But 16 Multiple CD4094 have strange problem as below.
I am Just using D0, CLK , STB. and Not using any external pull up at STM32 Side.
The problem is:
When I am sending Alternate data It works fine on all CD4094 IC.
When I am sending Same data It does Not work properly on all CD4094 .
Is there any mistake in configuration of STM32 GPIO.
Please Help me to sort out issue . Please Check attachments of STM32 and Below Code.
--
Karan123
unsigned char BufferCD4094[20] ;
int i ;
for( i=0; i<=16; i++)
{
BufferCD4094[i] = 0xFF ;
}
WriteOnCD4094() ;
HAL_Delay(20);
#define CL_1 15 //Not working Fine
/* USER CODE END WHILE */
if((HAL_GPIO_ReadPin(GPIOE, SW4_Pin) == 0))
{
HAL_Delay(20);
if((HAL_GPIO_ReadPin(GPIOE, SW4_Pin) == 0))
{
LCDGotoxy(2,0) ;
LCDString("Scrolling - 16 Cards") ;
LCDGotoxy(3,0) ;
LCDString("LEDs 2 Seconds") ;
while (1)
{
for( i=0; i<=CL_1; i++)
{
BufferCD4094[i] = 0xFE ;
}
WriteOnCD4094() ;
HAL_Delay(2000);
for( i=0; i<=CL_1; i++)
{
BufferCD4094[i] = 0xFD ;
}
WriteOnCD4094() ;
HAL_Delay(2000);
for( i=0; i<=CL_1; i++)
{
BufferCD4094[i] = 0xFB ;
}
WriteOnCD4094() ;
HAL_Delay(2000);
for( i=0; i<=CL_1; i++)
{
BufferCD4094[i] = 0xF7 ;
}
WriteOnCD4094() ;
HAL_Delay(2000);
for( i=0; i<=CL_1; i++)
{
BufferCD4094[i] = 0xEF ;
}
WriteOnCD4094() ;
HAL_Delay(2000);
for( i=0; i<=CL_1; i++)
{
BufferCD4094[i] = 0xDF ;
}
WriteOnCD4094() ;
HAL_Delay(2000);
for( i=0; i<=CL_1; i++)
{
BufferCD4094[i] = 0xBF ;
}
WriteOnCD4094() ;
HAL_Delay(2000);
for( i=0; i<=CL_1; i++)
{
BufferCD4094[i] = 0x7F ;
}
WriteOnCD4094() ;
HAL_Delay(2000);
}
}
}
void WriteOnCD4094(void)
{
char mm,kk;
HAL_Delay(20);
HAL_GPIO_WritePin(GPIOB, CLK_Pin ,GPIO_PIN_SET);
HAL_Delay(2);
HAL_GPIO_WritePin(GPIOE, STB_Pin ,GPIO_PIN_SET);
HAL_Delay(2);
for(kk=0;kk <=15;kk++)
{
for(mm =0 ; mm < 8 ; mm++)
{
if(BufferCD4094[kk] & 0x80)
HAL_GPIO_WritePin(GPIOA, D0_Pin , GPIO_PIN_SET);
else
HAL_GPIO_WritePin(GPIOA, D0_Pin , GPIO_PIN_RESET);
if(BufferCD4094[kk] & 0x80)
HAL_GPIO_WritePin(GPIOA, D1_Pin , GPIO_PIN_SET);
else
HAL_GPIO_WritePin(GPIOA, D1_Pin , GPIO_PIN_RESET);
if(BufferCD4094[kk] & 0x80)
HAL_GPIO_WritePin(GPIOA, D2_Pin , GPIO_PIN_SET);
else
HAL_GPIO_WritePin(GPIOA, D2_Pin , GPIO_PIN_RESET);
if(BufferCD4094[kk] & 0x80)
HAL_GPIO_WritePin(GPIOA, D3_Pin , GPIO_PIN_SET);
else
HAL_GPIO_WritePin(GPIOA, D3_Pin , GPIO_PIN_RESET);
if(BufferCD4094[kk] & 0x80)
HAL_GPIO_WritePin(GPIOC, D4_Pin , GPIO_PIN_SET);
else
HAL_GPIO_WritePin(GPIOC, D4_Pin , GPIO_PIN_RESET);
if(BufferCD4094[kk] & 0x80)
HAL_GPIO_WritePin(GPIOC, D5_Pin , GPIO_PIN_SET);
else
HAL_GPIO_WritePin(GPIOC, D5_Pin , GPIO_PIN_RESET);
if(BufferCD4094[kk] & 0x80)
HAL_GPIO_WritePin(GPIOB, D6_Pin , GPIO_PIN_SET);
else
HAL_GPIO_WritePin(GPIOB, D6_Pin , GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB,CLK_Pin , GPIO_PIN_SET) ;
DelayCLCard(20) ;
BufferCD4094[kk] <<=1; // Shift 1 bit left
HAL_GPIO_WritePin(GPIOB,CLK_Pin , GPIO_PIN_RESET) ;
DelayCLCard(20) ;
}
}
HAL_Delay(2);
HAL_GPIO_WritePin(GPIOE,STB_Pin,GPIO_PIN_RESET) ;
HAL_Delay(2);
}
Below Code is working Fine. When sending alternating data on CD4094.
if((HAL_GPIO_ReadPin(GPIOE, SW2_Pin) == 0))
{
HAL_Delay(20);
if((HAL_GPIO_ReadPin(GPIOE, SW2_Pin) == 0))
{
LCDGotoxy(2,0) ;
LCDString("Diagonal 16-Cards") ;
LCDGotoxy(3,0) ;
LCDString("LEDs 2 Seconds") ;
while (1)
{
BufferCD4094[0] = 0xFE ;
BufferCD4094[1] = 0xFD ;
BufferCD4094[2] = 0xFB ;
BufferCD4094[3] = 0xF7 ;
BufferCD4094[4] = 0xEF ;
BufferCD4094[5] = 0xDF ;
BufferCD4094[6] = 0xBF ;
BufferCD4094[7] = 0x7F ;
BufferCD4094[8] = 0xFE ;
BufferCD4094[9] = 0xFD ;
BufferCD4094[10] = 0xFB ;
BufferCD4094[11] = 0xF7 ;
BufferCD4094[12] = 0xEF ;
BufferCD4094[13] = 0xDF ;
BufferCD4094[14] = 0xBF ;
BufferCD4094[15] = 0x7F ;
WriteOnCD4094() ;
HAL_Delay(4000);
BufferCD4094[0] = 0xFF ;
BufferCD4094[1] = 0xFF ;
BufferCD4094[2] = 0xFF ;
BufferCD4094[3] = 0xFF ;
BufferCD4094[4] = 0xFF ;
BufferCD4094[5] = 0xFF ;
BufferCD4094[6] = 0xFF ;
BufferCD4094[7] = 0xFF ;
BufferCD4094[8] = 0xFF ;
BufferCD4094[9] = 0xFF ;
BufferCD4094[10] = 0xFF ;
BufferCD4094[11] = 0xFF ;
BufferCD4094[12] = 0xFF ;
BufferCD4094[13] = 0xFF ;
BufferCD4094[14] = 0xFF ;
BufferCD4094[15] = 0xFF ;
WriteOnCD4094() ;
HAL_Delay(4000);
}
}
}
2019-04-05 02:47 PM
Verify that you are always sampling the serial data 180 degrees out of phase.
In other words if you are sampling data on the same edge as the data is changing, your clock edge is very critical.
The CD4094 has a delayed serial data output Q' ( IIRC ) that helps with this problem.
To test for this place small capacitor (200pF- 470pF) on the data line in critical areas.