add config baud increase docs

This commit is contained in:
soypat
2024-01-14 20:16:45 -03:00
parent d5db138d9a
commit 97ef4986ba
3 changed files with 17 additions and 9 deletions
+14 -8
View File
@@ -17,18 +17,19 @@ const (
var (
spibus = machine.SPI0
)
func main() {
time.Sleep(time.Second)
SPI_CS_PIN.Configure(machine.PinConfig{Mode: machine.PinOutput})
err := spibus.Configure(machine.SPIConfig{
spicfg = machine.SPIConfig{
Frequency: 250000,
Mode: 0,
SCK: SPI_SCK_PIN,
SDO: SPI_TX_PIN,
SDI: SPI_RX_PIN,
})
}
)
func main() {
time.Sleep(time.Second)
SPI_CS_PIN.Configure(machine.PinConfig{Mode: machine.PinOutput})
err := spibus.Configure(spicfg)
if err != nil {
panic(err.Error())
}
@@ -38,9 +39,14 @@ func main() {
if err != nil {
panic("sd card init:" + err.Error())
}
// After initialization it's safe to increase SPI clock speed.
csd := sdcard.CSD()
kbps := csd.TransferSpeed().RateKilobits()
spicfg.Frequency = uint32(kbps * 1000)
err = spibus.Configure(spicfg)
cid := sdcard.CID()
pname := cid.ProductName()
csd := sdcard.CSD()
if !cid.IsValid() {
copy := cid.RawCopy()
println("CID not valid: theirCRC=", cid.CRC7(), "ourCRC=", sd.CRC7(copy[:15]))
+2
View File
@@ -58,6 +58,8 @@ func (c *SPICard) csEnable(b bool) { c.cs(!b) }
func (c *SPICard) LastReadCRC() uint16 { return c.lastCRC }
func (c *SPICard) LastR1() r1 { return c.lastr1 }
// Init initializes the SD card. This routine should be performed with a SPI clock
// speed of around 100..400kHz. One may increase the clock speed after initialization.
func (d *SPICard) Init() error {
dummy := d.buf[:]
for i := range dummy {
+1 -1
View File
@@ -447,7 +447,7 @@ var log10table = [...]int64{
1000000,
}
// RateMegabits returns the transfer rate in megabits per second.
// RateMegabits returns the transfer rate in kilobits per second.
func (t TransferSpeed) RateKilobits() int64 {
return 100 * log10table[t&0b111]
}