Hot answers tagged

80

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 "master" device, which initiates communications and supplies the clock which controls the data transfer rate. There can be one or more slaves. For more than one slave,...


18

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 you use a different pin for the slave select (SS) on each SPI device. When you want to talk to one slave, you hold its SS low and drive the other high. Do the ...


11

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 a dummy byte though, if the slave has nothing to say. So for 24 bits, simply clock out 3 bytes without deasserting the select. Since SPI is a synchronous ...


11

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 instruction of the author of SDFat library from this post. According to fat16lib, to increase the data rate we need to use flush() wisely. We would want to write() the ...


7

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 must send no faster than the slave device can handle. In the case of the AD5685R, that is 50 MHz. For multibyte transfer, you keep the chip select asserted (low)...


6

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(). If you change your code where there are references to Wire.send() and change to Wire.write() and also change Wire.receive() to Wire.read(), you should find ...


6

Each spi peripheral has its own protocol in the sense of commands and addresses if any and data. Spi simply makes a common ground for chip select vs clocks and clocks vs data and separate miso and mosi data lines. So a general purpose library doesnt make sense. Also spi certainly is not limited to a byte, many peripherals and many spi controllers allow ...


6

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 buffer transfer faster than transferring bytes individually using SPI.transfer(val); the switch to buffer transfers is one of the reasons my library is about 3.5 ...


6

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 think you could put SPI.h (and other things, like Wire.h) in the main .ino file, even if they aren't used due to your configuration parameters. The linker ...


5

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, SS pin (#8 on package), also labeled as "(SS/PCINT0) PB0", is left unconnected. Is it possible that PB0 is also configured as input somewhere in your program ...


5

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 boards.txt, or because the hardware is somehow different from what is expected. Given that you are using a bare ATmega328P, assuming that you've selected the ...


4

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 deals with the rest of your code, and then it generates another 8 clock cycles of 8MHz. The overall frequency is evidently sensed as 3.439 MHz. To generate a ...


4

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.transfer(0x00); } }


4

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 to use an expander of some sort, or use a Mega or Due for additional inputs or outputs.


4

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 uint8_t MISO = 14; static const uint8_t SCK = 15; Use SS MOSI MISO and SCK in your code


4

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 sensor or RTC. This will teach you the basics of sending commands via the Wire library. You might even get the hang of it just by looking at existing libraries. ...


4

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 use compatibility function with the standard SD Library. Try it out. 2. Your Hardware You should use a high class SD Card. As you maybe know SD Cards are ...


4

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've just fixed it out. The problem is the handshake when you call the SD.write(). Instead: //for each loop, it is going to make a handshake while(<...


4

I did not check the datasheet of the RF69, but it is customary for SPI devices to have a “slave select” input pin. When such a device is not selected, it will leave its MISO pin in high impedance and completely ignore whatever may happen on the MOSI and SCK pins. This effectively disconnects the device from the SPI bus. In this situation you show be able to ...


4

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. Wire it like you would any other I2C device.


4

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 something you shouldn't be. As pointed out on the Arduino forum, your for loop which tests for: i < sample2 || i >= sample2 will always be true. Of course ...


4

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, which itself is like EEPROM in concept. You may possibly have problems with storing the notes in RAM, and then writing them to the SD card fast enough not to lose some. ...


4

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 of loop() to print the desired info.


4

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 DATA is an output the data from DATA goes to MISO and voltage is dropped safely across R1 to the sink or source of MOSI depending on what state it is in. In ...


4

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. This will take 16 * 2 (raw data + 3 bytes for the pulse data = 35 bytes per 16 samples, meaning 35 bytes/samples * 20 samples/s = 700 bytes (I think your ...


3

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 (!(SPSR & _BV(SPIF))) ; // wait return SPDR; It should be perfectly possible to use SPI within the interrupt - indeed there is portions of the SPI API that deal ...


3

Looking at the datasheet for the MFR522, it is not clear that it even supports multidrop SPI. It does not mention anything about the state of the SPI output pins when the chip is not selected. It also mentions that the chip uses the slave select line to detect what communication mode to use upon startup, but does not mention anything about how the chip will ...


3

It is extremely confusing to have a variable val and then use _val in your function but then: shiftOut(dataPin,clockPin,LSBFIRST,val); As James pointed out, you are not sending the value passed to the function, to the shift register. Also this is just going to give you a boolean: updateRegister(!i); Why take "not i" there? I suggest you use SPI and ...


3

Yes, you can get SPI bus contention when using multiple SPI slave devices. It is up to you, the designer, to ensure that each SPI slave device has its chip select (CS or SS) asserted only when no other devices are driving MISO. Normally that is achieved by: initialize all of the CS pins high (inactive) during setup in the code that accesses SPI device #1, ...


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