我這邊用arduino寫了個于ch376sspi連接的程序,但是測試的時候總是返回的數(shù)值是56063,現(xiàn)在求解答
#define uint unsigned int #define uchar unsigned char
#define SCK 2 #define SDO 3 #define SDI 4 #define SCS 5
#define CMD_SET_USB_MODE 0x15 #define CMD_RD_USB_DATAO 0x27 #define CMD_SET_FILE_NAME 0x2f #define CMD_Disk_Connect 0x30 #define CMD_Disk_Mount 0x31 #define CMD_FILE_OPEN 0x32 #define CMD_FILE_CLOSE 0x36 #define CMD_BYTE_READ 0x37 #define CMD_BYTE_RD_GO 0x55
#define Working_Model 0x06
#define xEndCmd() digitalWrite(SCS,HIGH);
void Write_Byte(uchar data);
void setup() { ?pinMode(2,OUTPUT); ?pinMode(3,INPUT); ?pinMode(4,OUTPUT); ?pinMode(5,OUTPUT); ?pinMode(6,OUTPUT); ?Serial.begin(9600); }
void loop() { ?//uint a; ?test_ch376(); ?Serial.print(test_ch376()); ?Serial.print(" ?"); ?// //test_ch376(); // Serial.println(); ? }
void Write_Byte(uint data){ ?uchar i; ?for(i=0;i<8;i++){ ? ?if(data & 0x80)digitalWrite(SDI,HIGH); ? ?else digitalWrite(SDI,LOW); ? ?data<<=1; ? ?digitalWrite(SCK,HIGH); ?} }
uint Read_Byte(void){ ?uint i,d; ?for(i=0;i<8;i++){ ? ?digitalWrite(SCK,LOW); ? ?d<<=1; ? ?if(digitalRead(SDO))d++; ? ?digitalWrite(SCK,HIGH); ?} ?return d; }
void Write_Cmd(uint Cmd){ ?digitalWrite(SCS,HIGH); ?delayMicroseconds(5); ?digitalWrite(SCS,LOW); ?Write_Byte(Cmd); ?delayMicroseconds(15); }
void Write_Data(uint Data){ ?Write_Byte(Data); ?delayMicroseconds(5); }
uint Read_Data(){ ?delayMicroseconds(5); ?return Read_Byte(); }
uint test_ch376(){ ?delay(50); ?Write_Cmd(0x06); ?Write_Data(0x55); ?return Read_Data(); }
這個是我的程序
void Write_Byte(uint data)函數(shù),時鐘都沒有低電平。
命令最后也沒有拉高cs