[Tinyos-devel] Re: I2C and SPI sharing

Max CORTIANA max.cortiana at st.com
Thu Oct 12 10:58:05 PDT 2006


Here the Minimal Code:
I2C is done, while nothing is sent to CC2420 over SPI

Here's the Module. Wiring is over.

module I2Capp
{
  uses interface I2CPacket<TI2CBasicAddr> as I2CBasicRegister;
  uses interface Boot;
  uses interface HplMsp430GeneralIO as HplMsp430GeneralIOADC;
  uses interface HplMsp430GeneralIO as HplMsp430GeneralIOInterrupt;
  uses interface Leds;
  uses interface Resource;

  uses interface Packet as UartPacket;
  uses interface AMSend as UartSend;
  uses interface SplitControl as UartControl;
}

implementation
{
  uint8_t buffer[10];
  message_t myMsg;
  message_t pMsg;

  task void test(){
    buffer[0] = 0x00;
    if (call I2CBasicRegister.write(I2C_START|I2C_STOP, 0x1D, 1, 
&buffer[0]) != SUCCESS){
      post test();
    }
    return;
  }

  event void Boot.booted()
  {
    call HplMsp430GeneralIOADC.makeInput();
    call HplMsp430GeneralIOInterrupt.makeInput();
    call UartControl.start();
  }

  async event void I2CBasicRegister.writeDone(error_t error, uint16_t 
addr, uint8_t length, uint8_t *data) {
    call Resource.release();
    return;
  }

  async event void I2CBasicRegister.readDone(error_t error, uint16_t 
addr, uint8_t length, uint8_t *data){
    return;
  }

  task void sendTask(){
    if (call UartSend.send(AM_BROADCAST_ADDR, &pMsg, sizeof(pMsg)) != 
SUCCESS) {
      post sendTask();
    }
    return;
  }

  event void Resource.granted(){
    post test();
    post sendTask();
    return;
  }

  event void UartControl.startDone(error_t error) {
    call Resource.request();
  }
 
  event void UartControl.stopDone(error_t error){
    return;
  }

  event void UartSend.sendDone(message_t *msg, error_t error){
  }
 
}


--------------------------------------------------------------------------------------------------------------------------------
Wiring:

#include "I2C.h"
#include "oscilloscope.h"

configuration I2CappC
{
}
implementation
{
  components MainC, I2Capp, LedsC;

  I2Capp.Boot -> MainC.Boot;

  components HplMsp430GeneralIOC;
  I2Capp.HplMsp430GeneralIOADC -> HplMsp430GeneralIOC.ADC3;
  I2Capp.HplMsp430GeneralIOInterrupt -> HplMsp430GeneralIOC.Port20;
  I2Capp.Leds -> LedsC;
 
  components new Msp430I2CC();
  I2Capp.I2CBasicRegister->Msp430I2CC;
  I2Capp.Resource -> Msp430I2CC;

  //components SerialActiveMessageC as Message;
  components ActiveMessageC as Message;
  I2Capp.UartControl -> Message;
  I2Capp.UartPacket -> Message.Packet;
  I2Capp.UartSend -> Message.AMSend[AM_OSCILLOSCOPE];
}




Jonathan Hui wrote:
> Where are you making this change?
>
> It looks like it's either a problem with configuring the SPI or the
> arbiter, which signals events to configure the SPI.
>
> Just to confirm, are you seeing that exact order of events with
> setModeSpi() occurring between 2 and 3? If so, it's probably not the
> arbiter itself.
>
> The code to configure/unconfigure the SPI has also changed somewhat
> recently. Though I don't see anything obious in the code. Vlado or
> Philipp, do you have any ideas?
>
> A few additional questions:
> - Does SpiByte.write() always fail after using the I2C for the first
> time? Or after some number of I2C request()/release() cycles?
> - Does it still fail if you simply request()/release() the I2C
> resource but don't actually send any I2C packets in between?
> - Can you send minimal code that reproduces the problem?
>



More information about the Tinyos-devel mailing list