Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from fpioa_manager import fm, board_info
- from Maix import GPIO
- from machine import SPI
- import time
- import lcd
- import image
- img = image.Image()
- img.draw_rectangle(0, 0, 320, 240, color=(255, 0, 0),fill=True)
- lcd.init(freq=15000000)
- lcd.display(img)
- fm.register(21,fm.fpioa.GPIOHS0)#cs
- #fm.register(21,fm.fpioa.SPI1_SS0)#cs
- fm.register(24,fm.fpioa.SPI1_D0)#mosi
- fm.register(22,fm.fpioa.SPI1_D1)#miso
- fm.register(23,fm.fpioa.SPI1_SCLK)#sclk
- ss=GPIO(GPIO.GPIOHS0,GPIO.OUT)
- def spi_cs_on():
- ss.value(0)
- def spi_cs_off():
- ss.value(1)
- spi01=SPI(SPI.SPI1,mode=SPI.MODE_MASTER,baudrate=125000,polarity=1,phase=1,bits=8,firstbit=SPI.MSB,mosi=fm.fpioa.SPI1_D0,miso=fm.fpioa.SPI1_D1,sck=fm.fpioa.SPI1_SCLK,cs0=-1)
- #spi01=SPI(SPI.SPI1,mode=SPI.MODE_MASTER,baudrate=125000,polarity=1,phase=1,bits=8,firstbit=SPI.MSB,mosi=fm.fpioa.SPI1_D0,miso=fm.fpioa.SPI1_D1,sck=fm.fpioa.SPI1_SCLK,cs0=fm.fpioa.SPI1_SS0)
- spi_cs_off()
- buff=bytearray([0xff,0xff,0xff,0xff])
- spi_cs_on()
- spi01.write(buff, cs=SPI.CS0)
- spi_cs_off()
- time.sleep(0.1)
- for count in range(17280):
- # 16bit 1-shot
- buff=bytearray([0x08,0xa0])
- # 13bit 1-shot
- #buff=bytearray([0x08,0x20])
- spi_cs_on()
- spi01.write(buff, cs=SPI.CS0)
- spi_cs_off()
- count001 = 0;
- while True:
- time.sleep(0.01)
- # ステータスレジスタの読み込み
- buff=bytearray([0x40])
- spi_cs_on()
- spi01.write(buff,cs=SPI.CS0)
- status_reg = bytearray(spi01.read(1,0x00,cs=SPI.CS0))
- spi_cs_off()
- count001 += 1
- if count001 >= 100:
- break
- if ((status_reg[0] >> 7) & 1) == 0:
- break
- status_str = "status=0x{0:02x}, {1:d} ms".format(status_reg[0], count001*10)
- img.draw_rectangle(0, 0, 320, 240, color=(255, 0, 0),fill=True)
- #img.draw_string(10,50,status_str,color=(255,255,255),scale=2,mono_space=False)
- print(status_str)
- time.sleep(0.36)
- buff=bytearray([0x50])
- spi_cs_on()
- spi01.write(buff,cs=SPI.CS0)
- temp_raw = bytearray(spi01.read(2,0x00,cs=SPI.CS0))
- spi_cs_off()
- # 16bitの計算
- temp = (temp_raw[0]*256+temp_raw[1])
- if temp >= 32768:
- temp - 65536
- temp = temp / 128
- temp_str = "{0:.4f} Celsius".format(temp)
- img.draw_string(10,100,temp_str,color=(255,255,255),scale=5,mono_space=False)
- print("{0:.4f} ℃".format(temp))
- # 13bitの計算
- #temp = (temp_raw[0]*256+temp_raw[1])/8
- #if temp >= 4096:
- # temp - 8192
- #temp = temp / 16
- #print(temp)
- lcd.display(img)
- time.sleep(5.0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement