0
\$\begingroup\$

I created a circuit like the following:

Circuit

I have sub-circuits that all take serial data as input and do miscellaneous processing with it. Most of the sub-circuits are just light displays. I want to control such circuits with one microcontroller with simple code.

For simplicity, lets assume all these sub-circuits have no option for a data reset and that the only inputs allowed to them are clock and data into 74HC164's of each sub-circuit. I have illustrated that on the right-hand side of the shown circuit.

Due to PCB wiring and such, I ended up connecting pins 4 and 5 of the 74HC138 decoder to the TXD line which (according to several resources can function as a clock in serial mode 0). I connected pin 6 to a GPIO pin in an attempt to prevent false alarms.

What I want to do in software is to easily select any one device and send data to it preferably with the fewest instruction cycles as possible.

Because serial port mode 0 for 8051 is a good candidate, I thought about it by using code like this:

mov P1,#8Fh ;use 1st device
clr TI
mov SBUF,A ;A=8 bits of data
jnb TI,$ ;wait for full transmission
mov P1,#9Fh ;use 2nd device
clr TI
mov SBUF,A ;A=8 bits of data
jnb TI,$ ;wait for full transmission
clr TI
mov SBUF,A ;A=8 bits of data
jnb TI,$ ;wait for full transmission - here we sent 16 bytes to device 2.

That's the kind of code I ultimately like to use, but I feel theres a slight problem because if I'm not mistaken, one document online claimed the TXD line goes from low to high when it signals data is ready. and it makes me think TXD will stay low if no data is transmitted. If that document is correct, then if I choose to switch devices then the last device used will have a low to high transition (meaning an extra unwanted bit is to be processed).

My only other options are to explore other serial modes and if that wont work, I may have to bit bang or redo the entire hardware (which is an option I will not take).

Anyone have any solid solution to this?

\$\endgroup\$

bumped to the homepage by Community 1 hour ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • \$\begingroup\$ How does a device "know" that it has received a new byte of data? \$\endgroup\$ – Dave Tweed Jan 20 '18 at 1:11
  • \$\begingroup\$ Can't you just remove the ENABLE and drive the G1 input with CLOCK? CLOCK idles low so then HC138 is gated off and you can switch selector A/B/C at will. I'm not familiar with 8051 but Google hits seem to say TXD/CLOCK idles low. I don't see anything that says TXD/CLOCK goes high to indicate data ready. \$\endgroup\$ – Vince Patron Jan 20 '18 at 1:35
  • \$\begingroup\$ Its always fixed in 8-bit blocks. for some devices, I also have an option to manually start processing all data once it is received (by setting and clearing a bit). Other devices are on a timer in which if the data isn't changed within a certain time then it is assumed all data is processed. And no I can't drive G1 with the same clock because G1 must be high and G2A and G2B must be low input for an output to be low. \$\endgroup\$ – user152879 Jan 20 '18 at 2:49
  • \$\begingroup\$ does your microcontroller have a spare SPI or USART, both os those produce clock and data signals idea for programming shift registers, and sending a byte is usually as simple as writing to a single address \$\endgroup\$ – Jasen Jan 20 '18 at 10:37
0
\$\begingroup\$

the TXD line goes from low to high when it signals data is ready. and it makes me think TXD will stay low if no data is transmitted.

According to the Atmel 8051 Microcontrollers Hardware Manual TXD idles high. This is consistent with going from low to high when the data bit is 'ready' to be clocked into the receiver.

enter image description here

\$\endgroup\$

Your Answer

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