# using multiple shift registers

I am using Atmega128 and 8 shift registers 6D595 the ser_out of each register is connected to the next shift register's ser_in so they form a chain. There is no issue with the hardware it has been tested. I am using 4 16 bit variables to send data to shift registers. The problem that I am facing is that only once I am able to latch out the values only once. For example, if I send 4 variables as 0x0011,0xFF00,0x3c1d,0x1100 (they can be anything ) then I get the output on my 8 segment panel. but I am only able to update my registers only once. If I try to update them in a loop the program only shows the first value that I had sent to the shift register function.

Here is what I am doing in my shift out register

void shift_out(uint16_t data[4])
make latch pin HIGH
for(int x=0;x<3;x++)
{
for(int i=0;i<16;i++)
{
set data pin according to data[x]
give a low pulse to clock pin then make it high
}
}
give a low pulse to latch pin then make it high


If I call this function once it works perfectly fine.

But if I call it again with different values nothing happens

Please help me I am not sure what else information I am supposed to share. But I am willing to share anything. Thanks in advance!

Here is the complete function

void shift_out_data2(uint16_t data1,uint16_t data2,uint16_t data3,uint16_t data4) {

//PORTC |= (1<<(2));
//PORTC &= 0b11111011;
for(int i=0;i<16;i++)
{
if(data1 & (1<<(i)))
PORTC |= (1<<(3));
else
PORTC &= 0b11110111;

PORTC &= 0b11101111;   //Clock Pin
_delay_us(10);
PORTC |= (1<<(4));     //Clock Pin

}

for(int i=0;i<16;i++)      //same for loop as above but for next data
{
if(data2 & (1<<(i)))
PORTC |= (1<<(3));
else
PORTC &= 0b11110111;

PORTC &= 0b11101111;
_delay_us(10);
PORTC |= (1<<(4));

}
for(int i=0;i<16;i++)        //same for loop as above but for next data
{
if(data3 & (1<<(i)))
PORTC |= (1<<(3));
else
PORTC &= 0b11110111;

PORTC &= 0b11101111;
_delay_us(10);
PORTC |= (1<<(4));

}

for(int i=0;i<16;i++) //same for loop as above but for next data
{
if(data4 & (1<<(i)))
PORTC |= (1<<(3));
else
PORTC &= 0b11110111;

PORTC &= 0b11101111;
_delay_us(10);
PORTC |= (1<<(4));

}
PORTC |= 0b00000100;        //Latch Pin
_delay_us(10);
PORTC &= 0b11111011;}          //:Latch Pin


• Since you are sure that the problem is not in hardware, then something goes wrong in code. Could you provide the entire shift_out function without any pseudocode? – Egor Tamarin Apr 15 at 9:51