0

(I'm sorry for my bad English, but I will do my best)

I have a Chinese MUC which already programmed. It communicates with a LED driver chip using three wires (STB,CLK,DIN).
(LED driver controls 16 digit 7 Segment display)

After some research, I found that it can be talk to LED driver using shiftout function.

Now the main coal is to connect these 3 pins(STB,clk,din) to Arduino and read the incoming data and convert the data to numbers.

To test if this idea is working or not, I came with two arduino (uno to send shiftout function and mega to read it) after connect pin 2 of uno to pin 2 of mega and same 3 to 3, 4 to 4 and also Gnd of uno to Gnd of mega.
I wrote these codes:

arduino UNO side (to send shiftOut function)


    #define STB  4
#define clockPin  5
#define dataPin  6

void setup() {
  Serial.begin(9600);

  pinMode(STB, OUTPUT);
  pinMode(clockPin,  OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
 digitalWrite(STB, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 0b10101010 ); // 1st digit   
   digitalWrite(STB, HIGH);
}

arduino mega side (to read shiftOut function)


    #define STB 4
#define clockPin  5
#define dataPin  6

 int R_STB[8]; 
 int R_clockPin ;
 int R_dataPin ; 
void setup() {
   Serial.begin(115200);

  pinMode(STB, INPUT);
  pinMode(clockPin,  INPUT);
  pinMode(dataPin, INPUT);
}

void loop() {

 R_STB = digitalRead(STB); 
 R_clockPin = digitalRead(clockPin);
 R_dataPin = digitalRead(dataPin);


   for(int i=0 ; i<8;i++){
  Serial.print(R_STB[i]-2);

  Serial.print(" ");
  Serial.print (R_clockPin[i]);

 Serial.print(" ");
  Serial.print(R_dataPin[i]+2);
Serial.println(" ");
   }
 }

But the digital read at arduino mega side can't read all data due to it fast switching between High LOW statement maybe? and I am stuck here.

Please any one has any ideas?

  • 1
    Welcome to Arduino StackExchange. What the Chinenese MUC you have, provide us some the datasheets – abu-ahmed al-khatiri Aug 3 '19 at 14:31
1

You are right that you can't read the data fast enough with your method there. What you really need is the opposite of "shiftOut" - which happens to be called "shiftIn". You use it just like shiftOut, but instead of you sending it a value to send it instead returns a value that it reads.

You trigger it using the "STB" pin:

if (digitalRead(STB) == LOW) {
    uint8_t val = shiftIn(dataPin, clockPin, LSBFIRST);
    Serial.println(val, HEX);
}

But the protocol you describe is simply SPI. There is hardware within the Arduino to handle it for you. A little harder to work with, but it's capable of working at much higher speeds and is more likely to be able to read your incoming data fast enough.

Resources:

The latter includes how to configure an SPI "Slave" which is used for receiving data that is sent out from elsewhere.

| improve this answer | |
  • Majenko thank you vary much . I read about the SPI and i reach to the solution, one question please what if i got just two pin (DIN,CLK) instead of three(STB,CLK,DIN) how or what should i use? thank you in advance. – hatore Aug 5 '19 at 12:37
  • For SPI there must be a third pin. It may be labelled CS or SS instead of STB. Or it may not be SPI and have a "Latch" pin (it's a shift register in that case). If there's nothing but CLK and DIN then there must be some other non-standard method for indicating the start of a communication block. – Majenko Aug 5 '19 at 12:39
  • Thank you for your fast reply, The new LED driver (TM1640), it says in it datasheet "Dual-line serial interface (CLK, DIN) " . datasheet==>> datasheetspdf.com/pdf-file/838954/TitanMicro/TM1640/1 – hatore Aug 5 '19 at 12:44
  • It uses a non-standard system: The starting condition of data input is: when CLK is high, the DIN becomes low from high; the ending condition is: when CLK is high, the DIN becomes high from low. – Majenko Aug 5 '19 at 12:54
  • could you suggest any think which by reading it I can handle the data which comes from (MUC) through(CLK, DIN) pins using arduino?please – hatore Aug 5 '19 at 14:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.