Hi everyone, I'm trying to use the SPI interface in Mica2 mote but encountered
problems:
I programmed my own code instead of invoking the files in
"tinyos-2.x/tos/chips/atm128/spi".
My mica2 mote plays as "Master", and I only use it in single, that no other
devices are connected to it.
The SPI code I programmed includes:
1. Setting SPI pins direction;
2. Setting mode(clock, master/slave, LSB etc.);
3. Enabling SPI;
4. I don't use interrupt, so I use a timer to iterate the send/receive
operation every 1 milli-second;
5. Write to SPDR, then check SPIF value, then read SPDR, then check SPIF again.
Now I can achieve:
1. After writing data into SPDR the SPI data register, the SPIF flag signal
becomes "1";
2. Then reading SPDR gives me "the same data" what I write into SPDR;
3. Then checking SPIF gives me "0", showing that flag signal has been cleared (
due to the procedure as written in Atmega128 datasheet---firstly check SPIF,
then read SPDR);
4. Using osciliscope to see output waveform of pins:
For SCK it's right clock waveform 8 periods every 1 ms;
For MOSI (the data I want to send out, it's floating pin connecting to
nothing) it's 3.3V high level without any wave;
For MISO (which is floating pin, connects to nothing) it's 3.3V high level
but with "random squre waves" with variously changing duty ratio, and these
random squre waves' value has no relation with my sent data
Then I think maybe it's because I didn't use "Resource[uint id]" to request a
resource, because from the schematic I see MOSI and MISO share their pins with
USART_TX and USART_RX respectively. So I tried to add "Resource" and
"ArbiterInfo" functions into my code. Here I am confused:
What is the "id" value I should use for "Resource[uint id]"?
I tried two possiblities:
1. I use "Atm128_SPDR_t" referring to "Atm128Spi.h", and the codes can be
compiled, but the result is still as depicted before (right signal on SCK, no
signal on MOSI, random signal on MISO);
2. Because in example code Atm128SpiC, the implementation has such sentence
"components new SimpleFcfsArbiterC("Atm128SpiC.Resource")", so I use
CLIENT_ID=unique("Atm128SpiC.Resource") as ID for Resource[id]. The codes also
works, but the result doesn't change at all.
I think if I only use one function which is SPI, there's no neccesity to
request for Resource, because there's no conflict for the pins. Am I right?
However, using Resource or not, I still get the same wrong result: there's no
output signal in MOSI. I've tried different clock rates, but it seems have
nothing to do with speed.
So can anyone tell me how to slove this problem? And if I want to use Resource,
what's the ID number for SPI in mica2?
I've struggled to fix the problem for one week but get nothing, so I really
need your guys' help. Thanks a lot !_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help