vendredi 31 juillet 2015

Trying to bit-bang TPIC6C595 shift register but no output

The code is for an AVR atamega168xplained mini board, with an ATmega168pb MCU. The shift register I am using is a Texas Instruments TPIC6C595 I have the drain outputs of the shift register connected to the anodes of 8 LEDs. The OE(G) pin of shift register is tied to GND, and CLR tied to 5V. There is a 100nF ceramic capacitor between shift register VCC and GND. SER OUT is left unconnected to anything since I am trying to bit-bang just this one before I move up to chaining shift registers.

What happens is that I get no output from the shift register, all drain outputs are low (tested with multimeter). When I disconnect the SER IN, SRCK, and RCK from the microcontroller i get some flickering on only one of the LEDs which I guess is a result of those pins floating and being in an undefined state. I would have expected at least to get some kind of garbage output even if the code was wrong, but I get more of an output with the microcontroller completely disconnected. I know it is outputting a signal because I can connect it to the LEDS without the shift register and see they are lit up at various levels of intensity but do not have an oscilloscope to be able to actually look at the signals.

This is the code, with the defines for the output port at the top of the file included so it's clear what's being done:

#define DDR_SREG    DDRD
#define PORT_SREG   PORTD
#define SRCK        _BV(PORTD0)
#define RCK         _BV(PORTD1)
#define SER         _BV(PORTD2)

void display_write(uint8_t data)
{
    char i;

    PORT_SREG &= ~RCK;           // latch low

    for (i = 0; i < 8; ++i) {
        PORT_SREG &= ~SRCK;     // clock low
        if (data & 1)           // serial out
            PORT_SREG |= SER;
        else
            PORT_SREG &= ~SER;
        PORT_SREG |= SRCK;      // clock high
        data >>= 1;             // shift data
    }

    PORT_SREG |= RCK;           // latch high
}

Aucun commentaire:

Enregistrer un commentaire