BIT Banging serial from CPX

Microsoft's MakeCode platform for easy blocks-style programming

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bhedrick
 
Posts: 6
Joined: Sat Sep 01, 2012 1:09 pm

BIT Banging serial from CPX

Post by bhedrick »

Has anyone had any luck getting CPX to talk serial to another device?

I have used both a scope and a Saleae Logic to try to get things working. What I am finding is that the timing of code executing doesn't seem to be consistent and as a result the baud rate can end up varying enough that the highs and lows are detected properly either leading to incorrect values/letters or framing errors.

Here's the project: https://makecode.com/_Ak7FePYy7cwL

Here's my Makecode function. Notice I have removed loops in an effort to try to figure out if I can address the timing issue. The code is implemented using MSB for data transfer.

Code: Select all

function sendSerialText2() {
    messageToSend = "Goodbye My Friend!"
    numChars = messageToSend.length
    currChar = 0
    for (let index7 = 0; index7 <= numChars - 1; index7++) {
        currChar = messageToSend.charCodeAt(index7)
        pins.A6.digitalWrite(false)
        control.waitMicros(94)
        if (currChar & 128) {
            pins.A6.digitalWrite(true)
        } else {
            pins.A6.digitalWrite(false)
        }
        control.waitMicros(94)
        if (currChar & 64) {
            pins.A6.digitalWrite(true)
        } else {
            pins.A6.digitalWrite(false)
        }
        control.waitMicros(94)
        if (currChar & 32) {
            pins.A6.digitalWrite(true)
        } else {
            pins.A6.digitalWrite(false)
        }
        control.waitMicros(94)
        if (currChar & 16) {
            pins.A6.digitalWrite(true)
        } else {
            pins.A6.digitalWrite(false)
        }
        control.waitMicros(94)
        if (currChar & 8) {
            pins.A6.digitalWrite(true)
        } else {
            pins.A6.digitalWrite(false)
        }
        control.waitMicros(94)
        if (currChar & 4) {
            pins.A6.digitalWrite(true)
        } else {
            pins.A6.digitalWrite(false)
        }
        control.waitMicros(94)
        if (currChar & 2) {
            pins.A6.digitalWrite(true)
        } else {
            pins.A6.digitalWrite(false)
        }
        control.waitMicros(94)
        if (currChar & 1) {
            pins.A6.digitalWrite(true)
        } else {
            pins.A6.digitalWrite(false)
        }
        control.waitMicros(94)
        pins.A6.digitalWrite(true)
        control.waitMicros(94)
    }
}

User avatar
bhedrick
 
Posts: 6
Joined: Sat Sep 01, 2012 1:09 pm

Re: BIT Banging serial from CPX

Post by bhedrick »

While I don't have a solution for this issue, the project I am working on found a work-around, for now. We added an Arduino Micro in the middle. The goal was to talk to an LCD via an I2C backpack. With our short timeframes, we don't have time to implement something like the I2C LCD library from Adafruit in MakeCode.

Originally plan
CPX -> via serial just sending letters -> Arduino Micro -> serial -> serial backpack -> LCD

The workaround is
CPX -> via I2C just sending letters -> Arduino Micro -> via serial repeating letters -> Arduino Micro -> serial -> serial backpack -> LCD

We are aiming for
CPX -> via I2C just sending letters -> Arduino Micro (master and slave) -> serial -> serial backpack -> LCD

Locked
Please be positive and constructive with your questions and comments.

Return to “MakeCode”