Skip to content

Conversation

sago35
Copy link
Member

@sago35 sago35 commented Mar 29, 2021

I created SPI.TxN() to repeat SPI.Tx() n times.

// pseudo code
SPI.TxN(tx, rx []byte, n int) {
    for i := 0; i < n; i++ {
        SPI.Tx(tx, rx)
    }
}

SPI.Tx() is not enough to run ili9341 on standard SPI for speed reasons.
In particular, SPI.TxN() is faster than SPI.Tx() in the following applications.

SPI.Tx() is slower because it waits for the SPI to finish communication for each function call.

testcode:

package main

import (
	"fmt"
	"machine"
	"time"
)

func main() {
	//led := machine.LED
	//led.Configure(machine.PinConfig{Mode: machine.PinOutput})

	spi := machine.SPI0
	spi.Configure(machine.SPIConfig{
		SCK:       machine.SPI0_SCK_PIN,
		SDO:       machine.SPI0_SDO_PIN,
		SDI:       machine.SPI0_SDI_PIN,
		Frequency: 48000000,
	})

	txbuf := make([]byte, 4)
	rxbuf := make([]byte, 4)

	for i := range txbuf {
		txbuf[i] = byte(i * 2)
		rxbuf[i] = byte(i * 2)
	}

	testNo := 0
	for {
		//led.Toggle()
		time.Sleep(time.Millisecond * 500)

		switch testNo % 4 {
		case 0:
			// txrx
			spi.TxN(txbuf, rxbuf, 16)

			for i := range txbuf {
				if txbuf[i] != rxbuf[i] {
					fmt.Printf("%d : got %02X want %02X\r\n", i, rxbuf[i], txbuf[i])
				} else {
					fmt.Printf(".")
				}
				rxbuf[i] = 0
			}
		case 1:
			// tx
			spi.TxN(txbuf, nil, 16)
		case 2:
			// rx
			spi.TxN(nil, rxbuf, 16)
		case 4:
			// skip
		}

		testNo++
	}
}

The speed is about the same compared to #1453.

txrxn:
image

txn:
image

rxn:
image

@deadprogram deadprogram requested a review from aykevl April 2, 2021 15:19
@deadprogram
Copy link
Member

deadprogram commented Dec 6, 2024

@sago35 is this PR something you are still working on, or should we close it?

@sago35
Copy link
Member Author

sago35 commented Dec 7, 2024

@deadprogram
At this point, it would be better to adopt #3985. I will close this PR.

@deadprogram
Copy link
Member

Thanks for the reply @sago35 now closing.

@deadprogram deadprogram closed this Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants