Hi,
I am trying to read the device ID (manufacturer and device ID
information) from the serial flash chips found for instance on the xbow
mica family of motes. While I seem to be able to read the device status
byte correctly, I only ever get 0xFF values for the device ID.
The code below shows how I am trying to interface with the flash chip.
It is inspired by ${TOSROOT}/tos/chips/at45db/HplAt45dbByteC.nc.
Any ideas what I am doing wrong?
Cheers,
Urs
Data sheet (Atmel AT45DB041D):
http://www.atmel.com/dyn/resources/prod_documents/doc3595.pdf
//---------- TestAppC.nc ----------
#include "Test.h"
configuration TestAppC { }
implementation {
components TestC;
components MainC;
components LedsC;
components SerialActiveMessageC;
components new SerialAMSenderC(AM_TESTMSG);
components new TimerMilliC() as Timer;
components HplAt45dbIOC as Spi;
components BusyWaitMicroC;
MainC.Boot <- TestC;
TestC.Leds -> LedsC;
TestC.SerialControl -> SerialActiveMessageC;
TestC.SendData -> SerialAMSenderC;
TestC.Timer -> Timer;
TestC.Resource -> Spi.Resource;
TestC.SpiByte -> Spi.FlashSpi;
TestC.HplAt45dbByte -> Spi.HplAt45dbByte;
TestC.BusyWait -> BusyWaitMicroC;
}
//---------- TestC.nc ----------
module TestC {
uses {
interface Boot;
interface Leds;
interface SplitControl as SerialControl;
interface AMSend as SendData;
interface Resource;
interface SpiByte;
interface HplAt45dbByte;
interface Timer<TMilli> as Timer;
interface BusyWait<TMicro, uint16_t>;
}
}
implementation {
uint8_t state = 0;
bool sBusy = TRUE;
message_t sPacket;
uint8_t devid[NUM_BYTES];
event void Boot.booted() {
call SerialControl.start();
}
task void sendData() {
error_t error;
uint8_t i;
TestMsg* msg = (TestMsg*)call SendData.getPayload(&sPacket,
sizeof(TestMsg));
msg->state = state;
for(i = 0; i < NUM_BYTES; i++) {
msg->devid[i] = devid[i];
}
if(!sBusy) {
sBusy = TRUE;
error = call SendData.send(AM_BROADCAST_ADDR, &sPacket,
sizeof(TestMsg));
if(error != SUCCESS) {
sBusy = FALSE;
}
}
}
event void Timer.fired() {
call Resource.request();
}
event void HplAt45dbByte.idle() {
}
event void Resource.granted() {
uint8_t i;
if(state == 0) {
call HplAt45dbByte.select();
call SpiByte.write(0xD7); // device status: 0x9f
for(i = 0; i < NUM_BYTES; i++) {
devid[i] = call SpiByte.write(0x00);
}
call HplAt45dbByte.deselect();
call Resource.release();
post sendData();
} else {
call HplAt45dbByte.select();
call SpiByte.write(0x9F); // device id: 0x9f
for(i = 0; i < NUM_BYTES; i++) {
devid[i] = call SpiByte.write(0x00);
}
call HplAt45dbByte.deselect();
call Resource.release();
post sendData();
}
}
event void SerialControl.startDone(error_t error) {
if(error != SUCCESS) {
call SerialControl.start();
} else {
sBusy = FALSE;
call Timer.startPeriodic(4096);
}
}
event void SerialControl.stopDone(error_t error) {}
event void SendData.sendDone(message_t* msg, error_t error) {
if(state == 0) {
state = 1;
} else {
state = 0;
}
if(error == SUCCESS) {
sBusy = FALSE;
}
}
}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help