用户工具

站点工具


导航菜单

首页

Home


锤蚁出品

By TREEE


培训活动

Workshop


知识技术

Tech & Skills


里程碑

Milestone


加入我们

Opening

m:ws:ws4:slave

SPI Arduino端口模拟 从机程序

//Slave End
#define DI 11
#define CS 10
void setup() {
  attachInterrupt(digitalPinToInterrupt(2), get_sck, RISING); //SCK
  // put your setup code here, to run once:
  pinMode(CS, 0);
  pinMode(DI, 0);
  Serial.begin(9600);
}
 
void get_sck()
{
  static char buf = 0, buf_num = 0, is_cs = 0;
  if (digitalRead(CS) == 0 && is_cs == 0){
    is_cs = 1;
    buf_num = 0;
    buf = 0;
    Serial.println(' ');
  }
  else if(is_cs == 1)
  {
    buf <<= 1;
    buf |= digitalRead(DI)&0x01;
    Serial.print(digitalRead(DI));
    buf_num++;
    if (buf_num >= 8)
    {
      Serial.print(buf);
      is_cs = 0;
    }
  }
}
 
void loop() {
  // put your main code here, to run repeatedly:
 
}
· 最后更改: 2015/11/28 11:25