How to configure the SPI pins(MOSI,MISO,sclk and SS) for ATMEL ATSAM3X8E

atmelatmel-studioprogrammingspi

I am using ATMEL studio 6 for programming and novice in embedded systems.At present, I have read the theory working of SPI. I understand that I have to set particular bits to one in the control register for defining master or salve mode of operation and clock polarities, phase etc.

Problem:1) How to configure MOSI, clock and select_line as output pin from the master and MISO as the input pin to the master?.

2) Master and slave both are micro controllers,I just need to transfer and receive data to and from slave. So should the master code be dumped in the master mc and slave code should be dumped in slave mc? or both mc's must have the entire code into them?.

3) What are the main factors and key points should consider while SPI programming?.

Any help, suggestion and directions regarding this would be appreciated.Thanks.

Best Answer

  1. You use the DDRx register to define the direction of a pin (Data Direction Register). x is the name of the port you are using. Set the relevant bit to 1 for an output, and 0 for an input.

  2. Does your mouse have Windows installed on it? No. The same with microcontrollers. They only need the code on them to perform their own task. Why would the slave need the software that runs on the master?

  3. SPI is an incredibly simple protocol. The main thing to remember with it is it's full duplex and synchronous. If the slave needs to send data to the master then it is up to the master to request that data - the slave can't just send data at will to the master. Making sure the slave can respond to the SS signal fast enough is also important - you don't want to miss the first bit of the first byte coming in.