what does it means this code?
SPCR = (1<<SPE)|(1<<MSTR);
clr=SPSR;
clr=SPDR;
delay(10);
It is in the setup using SPI Library and more then one device MCP9221.
here the source http://mrbook.org/downloads/arduinosx150/SX150Driverarduino.pde
what does it means this code?
SPCR = (1<<SPE)|(1<<MSTR);
clr=SPSR;
clr=SPDR;
delay(10);
It is in the setup using SPI Library and more then one device MCP9221.
here the source http://mrbook.org/downloads/arduinosx150/SX150Driverarduino.pde
Giulialiuyi:
what does it means this code?SPCR = (1<<SPE)|(1<<MSTR);
clr=SPSR;
clr=SPDR;
delay(10);
It is in the setup using SPI Library and more then one device MCP9221. here the source http://mrbook.org/downloads/arduinosx150/SX150Driverarduino.pde
SPCR is the SPI Control register (part of the Arduino Processor)
SPE is a constant value of the Bit# in the SPCR register that Enables the SPI Hardware. it resolves to the number 6
MSTR is a constant value of the Bit# in the SPCR register that Selects MASTER SPI mode. It resolves to the number 4
So,
SPCR = (1<<SPE)|(1<<MSTR);
Walking thru this statement:
(1<<SPE) actually means Shift 1 6 binary positions to the left. it results in a value of B01000000.
(1<<MSTR) actually means Shift 1 4 binary positions to the left. it results in a value of B00010000.
| means or, applied to the previous values becomes
B01000000 | B00010000 which becomes B01010000
So this statement turns the SPI hardware on and Sets the hardware to Master Mode.
the next two operation are to clear any pending SPI Interrupt.
by reading the SPSR (SPI Status Register), and the SPDR (SPI Data Register) any pending SPI interrupt is cleared.
I don't know the reason for the delay of 10 milliseconds?
clr=SPSR;
clr=SPDR;
delay(10);
for more information on the Arduino (Atmel CPU's) here is the Spec Sheet Atmel AVR spec Sheet
Chuck.
Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.
THANK YOU A LOT!!!