![]() The constructor for the inbuilt SPI library appears to configure all 4 pins in the correct directions, so you shouldn't need to change them yourself, unless you are planning to use a different SS pin (in which case you also need to set that to output).īut as I said above, it appears that the library does not manage the SS pin for you apart from setting pin 10 as an output.A list of the 6000 libraries registered in the Arduino Library Manager. For example, this test code appears to "work", at least, connected to a logic analyzer: const char * test = "Hello world" ĭigitalWrite(SS_PIN, LOW) // this is pin 10 in SPI.hĪnalysing the Ethernet shield in operation appears to confirm that holding the SS pin low for extended transfers is perfectly normal. The library doesn't do this for you because it doesn't know for sure which pin you are going to use for the SS pin (you might have multiple peripherals).Īs for the 16 or more bits, I don't see what is stopping you sending more than 8 bits before raising SS back to high. This means you can usefully set it high and low yourself to tell your peripheral that you are about to send data to it (with SPI.transfer). If SS is configured as an output, the pin is a general output pin which does not affect the SPI system. The important thing is that pin 10 be configured as an output, the value of it is then ignore by the SPI hardware. I was initially confused about this too until I read the ATmega328 documentation. Note that even if you're not using the SS pin, it must remain set as an output otherwise, the SPI interface can be put into slave mode, rendering the library inoperative. ![]() If so, it sure would be nice if the hardware SPI lib had a function to send 16bits at once, or a function that sent a byte but didn't toggle the SS/CS pin at the start and end of the transmission. Now that sure sounds to me like the library is at fault here, and that the library must be the one setting the CS/SS pin high and low and that the hardware transfer that takes place has nothing to do with that pin's state being changed. Signal the end of packet by pulling high the Slave Select, SS line. The Master may continue to shift the next byte by writing it into SPDR, or If the SPI Interrupt Enable bit (SPIE) in the SPCR Register is set, an After shifting one byte, the SPI clock generator stops, setting the end of When this is done, writing aīyte to the SPI Data Register starts the SPI clock generator, and the hardware shifts the eightīits into the Slave. Must be handled by user software before communication can start. When configured as a Master, the SPI interface has no automatic control of the SS line. Posts by Grumpymike and others have indicated that you may need to bit bang if you want to send a 16 bit word to an SPI device because the Arduino's hardware can't handle that.īut I was reading the ATMega328's datasheet, and it had this to say on page 168: Yet from what I've read, it seems the Arduino's hardware SPI library sets the CS pin high after each bit you tell it to send. The DAC I want to talk to requores 16 bits before the CS pin goes high. Can I use it for something else without screwing up my communications, and without the communications messing with whatever's on the pin? ![]() The DAC has no way to send data back to the atmega, so that pin will be connected to nothing. If I can get away without connecting pin 10 to the DAC, can I put it to other use without issue, or will the hardware SPI mess with the pin? ![]() SPI may use any or all of the following:ĭ10 - CS aka Chip Select aka SS aka Slave Selectĭ11 - SDI aka ? aka MOSI aka Master Out Slave In aka Outputĭ12 - ? aka ? aka MISO aka Master In Slave Out aka Inputĭo I need to connect pin 10 to the DAC, if it is the only thing I am communicating with? Could I stick a pullup/pulldown resistor on the DAC's CS pin instead to keep it eneabled? I've already discovered that to do hardware SPI I need to connect my DAC to specific pins. I'm studying how to do hardware SPI because I don't think doing it in software is going to be fast enough to write to a DAC at the sampling rates I need.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |