Implementation of SPI Function-Simulink
29 次查看(过去 30 天)
显示 更早的评论
Hello everyone, Im trying to implement this SPI fucntion in a Simulink block to stablish communication with my Arduino MEga 2560 . It's an easy function, the problem is i dont't know where to start, Ive read for several days information in Internet,seen tutroial about S-functions, but I found the info really confusing.This is my function code :
void setup() {}
// the loop routine runs over and over again forever:
void loop() {}
// This is the generic initialization function to set up the Arduino to communicate with the chip.
void SPI_init() {
// initialize SPI for the dSPIN chip's needs:
// most significant bit first,
// SPI clock not to exceed 5MHz,
// SPI_MODE0 (clock idle low, latch data on rising edge of clock)
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV16); // System clock: 16MHz; Stepper SPI runs at 1MHz
SPI.setDataMode(SPI_MODE0);
Serial.println("SPI configured!");
}
I would really apreciate if someone could help me out :) :)
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!