使用sd卡可以扩大8266的存储器,使用时候很重要的是接线。
其他很容易。下面程序就是初始化、挂载sd卡、读sd卡里面main.cpp里面的代码行。
import machine, sdcard, os
from machine import Pin, I2C, ADC, SPI
#this file use to read file in sd
#use 8266 nodemcu,hardware hspi
#d5,d6,d7,d8 The hardware SPI is faster (up to 80Mhz),
#but only works on following pins: MISO is GPIO12, MOSI is GPIO13, and SCK is GPIO14
#because 8266 only one spi
#define pins for SD cardhspi = SPI(1, baudrate=80000000, polarity=0, phase=0)
spisd = SPI(1, baudrate=80000000, polarity=0, phase=0)
sd = sdcard.SDCard(spisd, machine.Pin(15,mode=Pin.OUT))
#mount SD card
try:
uos.mount(sd,'/sd') #clayton
except OSError:
print("error")
sleep_ms(500)
finally:
pass
print(os.listdir('/sd'))
fl=open('sd/main.cpp','r')
for i in range(6):
print(fl.readline())
版权声明:本文为CSDN博主「linchao100」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_57122083/article/details/122677076
使用sd卡可以扩大8266的存储器,使用时候很重要的是接线。
其他很容易。下面程序就是初始化、挂载sd卡、读sd卡里面main.cpp里面的代码行。
import machine, sdcard, os
from machine import Pin, I2C, ADC, SPI
#this file use to read file in sd
#use 8266 nodemcu,hardware hspi
#d5,d6,d7,d8 The hardware SPI is faster (up to 80Mhz),
#but only works on following pins: MISO is GPIO12, MOSI is GPIO13, and SCK is GPIO14
#because 8266 only one spi
#define pins for SD cardhspi = SPI(1, baudrate=80000000, polarity=0, phase=0)
spisd = SPI(1, baudrate=80000000, polarity=0, phase=0)
sd = sdcard.SDCard(spisd, machine.Pin(15,mode=Pin.OUT))
#mount SD card
try:
uos.mount(sd,'/sd') #clayton
except OSError:
print("error")
sleep_ms(500)
finally:
pass
print(os.listdir('/sd'))
fl=open('sd/main.cpp','r')
for i in range(6):
print(fl.readline())
版权声明:本文为CSDN博主「linchao100」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_57122083/article/details/122677076
暂无评论