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 "...
user avatar
  • 35.2k
22 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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 286
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 ...
user avatar
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(). ...
user avatar
  • 276
6 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. ...
user avatar
  • 102k
6 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 - ...
user avatar
  • 102k
5 votes
Accepted

util/delay.h from arduino _delay_ms not delaying in accurate time with my hardware configuration

At a 30000 ft. level, it's because the defined F_CPU value doesn't match your hardware. This can happen because the incorrect device is chosen in the IDE or because the device is misconfigured in ...
user avatar
5 votes
Accepted

Arduino: Hardware SPI hangs, bit-bang does not

According to ATmega32u4 datasheet, section 17.2.1 (SPI / SS Pin Functionality / Master Mode: If SS is configured as an input, it must be held high to ensure Master SPI operation. In your circuit, ...
user avatar
  • 8,829
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 ...
user avatar
  • 1,352
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 ...
user avatar
  • 35.2k
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, ...
user avatar
  • 35.2k
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
user avatar
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 ...
user avatar
  • 2,469
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 ...
user avatar
  • 102k
4 votes
Accepted

Can the SPI pins of an Arduino be separated from SPI?

No. Those pins are not separate on the microcontroller itself. If you need to use SPI and still need more pins you may use analog inputs as digital inputs or outputs. Otherwise you'll probably have ...
user avatar
4 votes
Accepted

Arduino Uno and Leonardo SPI clock can't be measured

Please note the SPI clock will only be active while it is shifting data. So simply put the spi.transfer in a hard loop #include <SPI.h> void setup() { SPI.begin(); while (1) { SPI....
user avatar
  • 2,443
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 (!(...
user avatar
  • 102k
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 ...
user avatar
  • 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 ...
user avatar
  • 35.2k
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 ...
user avatar
  • 5,595
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 ...
user avatar
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'...
user avatar
  • 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. ...
user avatar
  • 35.2k
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 ...
user avatar
  • 35.2k
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(...
user avatar
  • 7,821
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 ...
user avatar
  • 6,932

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