Hot answers tagged

108 votes
Accepted

How do you use SPI on an Arduino?

Introduction to SPI The Serial Peripheral Interface Bus (SPI) interface is used for communication between multiple devices over short distances, and at high speed. Typically there is a single "...
  • 35.5k
23 votes
Accepted

How to access multiple SPI interfaces on Arduino

Assuming you just want to connect two SPI slave devices to the SPI bus and use them in a mutually exclusive way under software control, with the Arduino as the master, then you just need to make sure ...
12 votes
Accepted

How to increase SD card write speed in arduino

OK. So, I tried the SDFat lib. This library is definitely better than the default SD library that comes with adruino. But that is not how I solved my problem of low data-rate. I followed the ...
11 votes
Accepted

How do I transfer more than 1 byte at once via SPI bus?

I believe Arduino's SPI.transfer waits to receive 8 bits after sending 8 bits. Incorrect. With SPI, a byte is clocked in at the same time as a byte is clocked out. It may be that this byte is simply ...
7 votes

How do I transfer more than 1 byte at once via SPI bus?

In the SPI protocol, you get one byte back for every one you send. If you are not interested in the response from a device, you can just ignore the return bytes. SPI has no handshaking. You just ...
  • 286
7 votes
Accepted

Confused between SPI and I2C for SSD1306 OLED

SCK and SCL are the same thing. Serial ClocK Serial CLock They seem to be interchangeable. The fact you have SDA (Serial DAta) as opposed to separate SDI / SDO or MOSI / MISO pins means it's I2C. ...
  • 103k
7 votes
Accepted

Is there any standard for colors of Serial Peripheral Interface wires?

No, there is no standard. However: Red is often +5V Black is often GND I often assign colours numerically according to the resistor colour code: 0 - Black 1 - Brown 2 - Red 3 - Orange 4 - Yellow 5 - ...
  • 103k
6 votes

How do I transfer more than 1 byte at once via SPI bus?

Note that there is also a version of SPI.transfer for multi-byte (buffer) transfers: SPI.transfer(buffer, size) I used the buffer transfer in my library for the TLC59711 (see code) and found the ...
6 votes

Undefined functions send() and receive() on TwoWire/SPI

This is caused by the sketch you downloaded being old. In prior releases, the methods called send() and receive() were used to send and receive SPI data. These were renamed to be write() and read(). ...
  • 276
5 votes
Accepted

Are there any constants for default SPI port pins defined?

Yes there are. They are defined in pins_arduino.h Below the pins for the yun. // Map SPI port to 'new' pins D14..D17 static const uint8_t SS = 17; static const uint8_t MOSI = 16; static const ...
  • 1,372
5 votes

How to include <SPI.h> outside the .ino file

See my answer How the IDE organizes things. There is no easy way to avoid having to put an include in the main .ino file, unless you write your own build process (or perhaps use another toolchain). I ...
  • 35.5k
5 votes
Accepted

Writing "theremin" outputs to a MIDI file on an SD card

The short answer would be "yes, it is possible". There are lots of gadgets around that record MIDI. They would have microprocessors in them, and they would have something like an SD card, ...
  • 35.5k
5 votes
Accepted

Wrong documentation for Mega2560 SPI Pins?

The image is incorrect, unfortunately. The SPI pins are below: PB0 - #SS PB1 - SCK PB2 - MOSI PB3 - MISO
5 votes
Accepted

Arduino Array Scope with SPI

When you call SPI.transfer(a, 4);, any "received data" is stored in your byte array, a[]. The original data is overwritten. If you print out the contents of the array before and after the ...
  • 2,496
4 votes
Accepted

What should the frequency reading of the SPI clock be with this code?

Yes, the clock speed should be (and most probably is) 8 MHz. However, you're not generating an 8 MHz clock. What you are in fact generating is 8 clock pulses of 8 MHz, then you have a delay while it ...
  • 103k
4 votes
Accepted

Usage of SPI inside an ISR

SPI doesn't use interrupts. It references the interrupt flag to know if a transfer has been completed, but it doesn't actually have interrupts enabled: SPDR = data; asm volatile("nop"); while (!(...
  • 103k
4 votes

Issue sharing MISO with multiple RC522 RFID Readers

I am joining this conversation VERY late, however maybe my answer can help someone who is just now looking into this. I was able to get SEVEN RC522 readers working on one Arduino! My solution was very ...
  • 61
4 votes

Convert library from using bitbanging to hardware SPI

The standard AVR library has SPI handling. See, for example: http://www.gammon.com.au/spi You don't have to write a library if you don't want, just communicate directly using SPI. The datasheet for ...
  • 35.5k
4 votes

Are there any detail examples of Si4463

I've looked at the data sheet for this and I think it is the wrong choice of device for a beginner. Can I suggest that you start by looking at a relatively simple DPI interfaced device, such as a ...
  • 5,606
4 votes

How to increase SD card write speed in arduino

Many factors would decide if you can reach this wanted speed. Only some of these. 1. Your Software The SdFat Library is faster than the standard SD Library of the Arduino IDE. It also has an easy to ...
4 votes

How to increase SD card write speed in arduino

Avoid the handshake getting a buffer! Use SD.write(buf,size); Hi every one, I'm working in a project with the same issue. I was following the same steps of yours and got exactly the same numbers. I'...
  • 41
4 votes

I2C and SPI at the same time?

is it possible to use I2C and SPI at the same time? Yes it is. Both are implemented in hardware in the chip. They can operate "in the background" and raise an interrupt when there is something to do. ...
  • 35.5k
4 votes

Why does void loop() stop after some samples?

float sine[5000] ... sine[j]=s+190; A float takes 4 bytes. You are allocating 5000 of them which is 20000 bytes. The Uno has 2048 bytes of RAM. Thus you are running out of RAM and overwriting ...
  • 35.5k
4 votes
Accepted

SPI.transfer(buffer, size) does not send data from buffer

SPI.transfer(&SPI_message,2) is unfortunately destructive. The buffer is updated with the received values. There is a SPI member function[1] that can be used for 16-bit data; SPI.transfer16(...
  • 7,881
4 votes

Can Serial be safely used in an SPI interrupt routine

Serial should be avoided in ISRs because interrupts are disabled inside ISRs, and Serial transmission uses interrupts to operate. Better to have the ISR set a flag that is read in the next iteration ...
  • 6,942
4 votes

Read write with half duplex SPI

All you need is a single resistor. simulate this circuit – Schematic created using CircuitLab When DATA is an input the data from MOSI passes through the resistor to both DATA and MISO. When ...
  • 103k
4 votes
Accepted

SPI: test by connecting MOSI to MISO

Yes, you can - and it's something I often do when doing low-level electrical testing an SPI interfacce. For every clock that you send out the data presented on MOSI will get reflected on MISO. So if ...
  • 103k
4 votes

Writing to sd card with a sampling rate 50ms or less? I have a sketch that writes to sd every 1s but jams at faster sampling rates. Please help?

Some tips: Do not open the open and close the file in every loop sequence (I think you can use the flush command to save/update the file. Do not save strings, but save the raw data and pulse string. ...
4 votes

SPI Slave Programming for Arduino

SPI.h library by default only support Master mode, the SPI.begin() will automatically set slave select (ss) pin to HIGH whether you have pinMode(ss, OUTPUT) in your setup() code or not and set the ...
  • 993

Only top scored, non community-wiki answers of a minimum length are eligible