We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I looked the example of the work with at250x0 and has not understood one thing. Why when sensing from memory in she is written 0xff? This program possible to find on request SPI here. Here is this fragment: while (length--) { SPDR = 0xFF; while ((SPSR & 0x80) == 0); *buf++ = SPDR; } About this in documentation on at250x0 is not written. This is some particularity?
You may want to read the article "How SPI Works" to gain a better understanding of SPI: http://www.embedded.com/story/OEG20020124S0116 According to this article: "Devices communicate using a master/slave relationship, in which the master initiates the data frame. When the master generates a clock and selects a slave device, data may be transferred in either or both directions simultaneously. In fact, as far as SPI is concerned, data are always transferred in both directions. It is up to the master and slave devices to know whether a received byte is meaningful or not." If you include the parts of the code that were left out, it makes more sense:
void read_at250x0 ( unsigned address, unsigned char *buf, unsigned length) { AT250X0_CS = 0; SPDR = AT250X0_READ_OPCODE(address); while ((SPSR & 0x80) == 0);
PDR = AT250X0_ADDRESS_LSB(address); while ((SPSR & 0x80) == 0);
while (length--) { SPDR = 0xFF; while ((SPSR & 0x80) == 0); *buf++ = SPDR; }
AT250X0_CS = 1; }