0
\$\begingroup\$

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 

I tried to add comments to it becomes readable ... i know its not an efficient code but its just for testing. Thanks!

Edit: I found out that the function doesn't return to main() even if i call it outside the while loop

\$\endgroup\$
  • \$\begingroup\$ 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? \$\endgroup\$ – Egor Tamarin Apr 15 at 9:51
  • \$\begingroup\$ Sure i can!!! Let me edit the post \$\endgroup\$ – Muhammad Sufyan Raza Apr 15 at 10:14
  • \$\begingroup\$ What is the schematic? What are the pins on PORTC doing? You should really define them like #define SHIFT_LATCH (1<<(2)) and then set/clear it like PORTC |= SHIFT_LATCH .... PORTC &= ~SHIFT_LATCH. Did you correctly set up those pins as outputs? I had a LOT I could say about this, but need more information. \$\endgroup\$ – Kurt E. Clothier May 6 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.