Jump to content

Talking to a 4094 shift register using the USCI module

Recommended Posts



I'm building a simple LED matrix display, using 4094's to drive the columns of the matrices, and I would like to use the universal serial module to clock the data into the shift registers.


So I set up a simple test, and had the serial module clock out 7 bits (I have three 7x5 matrix panels, and at first I'm just using one), but I didn't see the results I expected. When I got a scope on the outputs, I saw the serial module clocking out 11 bits! I had to set the bit counter register USICNT to 4 to convince the serial module to output 7 bits. The code looks something like

//set strobe high
P1OUT |= BIT3;
// load the data (this was a single bit moving through the byte)
USISRL = <data>;
// clock out 7 bits (!!)
// wait until they're out
// set strobe low, this will latch the outputs on the shift register
P1OUT &= ~BIT3;

I know that USICNT reaches zero at the point I expect, because I can see the strobe go low when the final bit is clocked out. But what is going on here? Does anyone know why seven bits get clocked out when I set USICNT to four?


Link to post
Share on other sites

Well it looks like the culprit was Grace - which I think loaded the USICNT register with 8, causing the SPI clock to start. So by the time I got to my code the clock had already been running for a bit, and so writing 8 to the register caused me to see about 12 bits on the output.


Once I threw away the grace project and started again doing everything by hand it all worked fine. I'm going to start another thread about this project because it involves a couple of custom boards and I don't want to have my stupid question at the top of the thread :)

Link to post
Share on other sites

I think you meant USI in the title not USCI...


Haven't read your code in detail yet but be aware there's an errata bug in USI modules--the very first xfer you do will send 1 more bit than you intended.


I get around that in my code implementations by doing a strawman xfer after initialization with none of the Chip Select lines for the attached peripherals active.


Sent from my Galaxy Note II with Tapatalk



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...