DAFTAR ISI
1. Kondisi
2. Gambar Rangkaian
3. Flowchart
4. Listing
5. Video Simulasi
6. Link Download
6. Link Download
1. Kondisi [Kembali]
Ganti LED menjadi Buzzer, Tambahkan resistor sebelum Buzzer sebesar 1k ohm.
2. Gambar Rangkaian [Kembali]
2. Gambar Rangkaian [Kembali]
3. Flowchart [Kembali]
4. Listing Program [Kembali]
Untuk MASTER
#include <SPI.h> //Deklarasi library SPI void setup (void) { Serial.begin(115200); //Set baud rate 115200 digitalWrite(SS, HIGH); // disable Slave Select SPI.begin (); SPI.setClockDivider(SPI_CLOCK_DIV8); //divide the clock by 8 } void loop (void) { char c; digitalWrite(SS, LOW); //enable Slave Select // send test string for (const char * p = "Hello, world!\r" ; c = *p; p++) { SPI.transfer (c); Serial.print(c); } digitalWrite(SS, HIGH); // disable Slave Select delay(2000); }
untuk SLAVE
#include <SPI.h>
char buff [50];
volatile byte indx;
volatile boolean process;
void setup (void) {
Serial.begin (115200);
pinMode(MISO, OUTPUT); // have to send on master in so it set as output
SPCR |= _BV(SPE); // turn on SPI in slave mode
indx = 0; // buffer empty
process = false;
SPI.attachInterrupt(); // turn on interrupt
}
ISR (SPI_STC_vect) // SPI interrupt routine
{
byte c = SPDR; // read byte from SPI Data Register
if (indx < sizeof buff) {
buff [indx++] = c; // save data in the next index in the array buff
if (c == '\r') //check for the end of the word
process = true;
}
}
void loop (void) {
if (process) {
process = false; //reset the process
Serial.println (buff); //print the array on serial monitor
indx = 0; //reset button to zero
}
}
5. Video Simulasi [Kembali]
6. Link Download [Kembali]
Download Rangkaian Disini
Download Video Disini
Download listing program master Disini
Download listing program slave Disini
Download HTML Disini
Untuk MASTER
#include <SPI.h> //Deklarasi library SPI void setup (void) { Serial.begin(115200); //Set baud rate 115200 digitalWrite(SS, HIGH); // disable Slave Select SPI.begin (); SPI.setClockDivider(SPI_CLOCK_DIV8); //divide the clock by 8 } void loop (void) { char c; digitalWrite(SS, LOW); //enable Slave Select // send test string for (const char * p = "Hello, world!\r" ; c = *p; p++) { SPI.transfer (c); Serial.print(c); } digitalWrite(SS, HIGH); // disable Slave Select delay(2000); }
untuk SLAVE
#include <SPI.h>
char buff [50];
volatile byte indx;
volatile boolean process;
void setup (void) {
Serial.begin (115200);
pinMode(MISO, OUTPUT); // have to send on master in so it set as output
SPCR |= _BV(SPE); // turn on SPI in slave mode
indx = 0; // buffer empty
process = false;
SPI.attachInterrupt(); // turn on interrupt
}
ISR (SPI_STC_vect) // SPI interrupt routine
{
byte c = SPDR; // read byte from SPI Data Register
if (indx < sizeof buff) {
buff [indx++] = c; // save data in the next index in the array buff
if (c == '\r') //check for the end of the word
process = true;
}
}
void loop (void) {
if (process) {
process = false; //reset the process
Serial.println (buff); //print the array on serial monitor
indx = 0; //reset button to zero
}
}
5. Video Simulasi [Kembali]
6. Link Download [Kembali]
Download Rangkaian Disini
Download Video Disini
Download listing program master Disini
Download listing program slave Disini
Download HTML Disini
Tidak ada komentar:
Posting Komentar