Results 1 to 7 of 7

Thread: OpenCM 9.04 and SPI

  1. OpenCM 9.04 and SPI

    Has anyone had any luck using the SPI ports on the OpenCM 904?
    Apparently it has 2, but I could not get either to talk to my AS5048A magnetic encoder.
    The same setup (device, cable) works well with an Arduino. I have tried all 4 clock modes, and different frequencies, but do not get any reasonable bytes out of it.

  2. #2

    Re: OpenCM 9.04 and SPI

    Have you asked up on the Robotis website? Not sure how well they are responding these days as I am not currently playing with Robotis stuff...

    Which Arduino? Which encoder... i.e. is your Arduino setup made to run at 5v or 3.3v?

    I think I tried a display or two on the OpenCM board, but not sure... Been awhile

  3. Re: OpenCM 9.04 and SPI

    It was the nano, with is 5v and the OpenCM is 3.3v. However the encoder is supposed to be dual voltage.
    Some of the code for the SPI looks a bit incomplete (with some TODOs for interrupts) so I'm not 100% convinced it will actually work.
    Maybe I can try a software SPI - at least I will get an idea whether any data is getting through.

  4. Re: OpenCM 9.04 and SPI

    The hardware library didn't seem to work - maybe I got the "mode" was wrong, and rising/falling edges were confused.
    Anyhow, the software version did work, and for reference it is:

    Code:
    struct SoftSPI
    {
      int ss;
      int clk;
      int mosi;
      int miso;
      
      SoftSPI(int inSS, int inClk, int inMosi, int inMiso) :
         ss(inSS), clk(inClk), mosi(inMosi), miso(inMiso)
      {
         pinMode(ss, OUTPUT);
         pinMode(clk, OUTPUT);
         pinMode(mosi, OUTPUT);
         pinMode(miso, INPUT);
         digitalWrite(ss,HIGH);
         digitalWrite(clk,HIGH);
      }
      
      unsigned int query()
      {
         // Select chip ...
         digitalWrite(ss, LOW);
         // Need 350 ns - 25 cycles @ 72Mhz?
         for(int i=0;i<10;i++)
            ;
         digitalWrite(mosi, HIGH);
         unsigned int result = 0;
         for(int bit=0;bit<16;bit++)
         {
           // latch MOSI (bit already set to 1) on falling edge...
           digitalWrite(clk,LOW);
           // Must wait 10ns - one clock cycle at 72Mz
           result <<=1;
           // latch MISO on rising edge- data from device.
           digitalWrite(clk,HIGH);
           if (digitalRead(miso))
             result |= 1;
          }
          // Finish select
          digitalWrite(ss, HIGH);
          // 14 bits ...
          return result & 0x3fff;
       }
    };
    
    
    
    
    SoftSPI softSpi(18, 19, 21, 20);

  5. #5

    Re: OpenCM 9.04 and SPI

    Again it has been a long time since I played with the OpenCM boards... And awhile since I tried SPI library on the board.

    But if I remember there are two SPI busses on the chip.
    If you look at the pin definition tables in variant.cpp:
    Code:
    extern const Pin2PortMapArray g_Pin2PortMapArray[]=
    {
        {GPIOA, GPIO_PIN_4,   &hADC1,   ADC_CHANNEL_4 , NULL   ,   NO_PWM       , 0       },  // 0
        {GPIOA, GPIO_PIN_5,   &hADC1,   ADC_CHANNEL_5 , NULL   ,   NO_PWM       , 1       },  // 1                  SPI1_SCK
        {GPIOA, GPIO_PIN_0,   &hADC1,   ADC_CHANNEL_0 , &hTIM2 ,   TIM_CHANNEL_1, 2       },  // 2
        {GPIOA, GPIO_PIN_1,   &hADC1,   ADC_CHANNEL_1 , &hTIM2 ,   TIM_CHANNEL_2, 3       },  // 3
        {GPIOA, GPIO_PIN_2,   &hADC1,   ADC_CHANNEL_2 , &hTIM2 ,   TIM_CHANNEL_3, 4       },  // 4                              UART1_TXD
        {GPIOA, GPIO_PIN_3,   &hADC1,   ADC_CHANNEL_3 , &hTIM2 ,   TIM_CHANNEL_4, 5       },  // 5                              UART1_RXD
        {GPIOA, GPIO_PIN_6,   &hADC1,   ADC_CHANNEL_6 , &hTIM3 ,   TIM_CHANNEL_1, 6       },  // 6                  SPI1_MISO
        {GPIOA, GPIO_PIN_7,   &hADC1,   ADC_CHANNEL_7 , &hTIM3 ,   TIM_CHANNEL_2, 7       },  // 7                  SPI1_MOSI
        {GPIOB, GPIO_PIN_0,   &hADC1,   ADC_CHANNEL_8 , &hTIM3 ,   TIM_CHANNEL_3, 8       },  // 8
        {GPIOB, GPIO_PIN_1,   &hADC1,   ADC_CHANNEL_9 , &hTIM3 ,   TIM_CHANNEL_4, 9       },  // 9
    
        {GPIOA, GPIO_PIN_8,   NULL,     NO_ADC        , &hTIM1 ,   TIM_CHANNEL_1, 10      },  // 10
        {GPIOA, GPIO_PIN_9,   NULL,     NO_ADC        , &hTIM1 ,   TIM_CHANNEL_2, 11      },  // 11                             UART2_TXD
        {GPIOA, GPIO_PIN_10,  NULL,     NO_ADC        , &hTIM1 ,   TIM_CHANNEL_3, 12      },  // 12                             UART2_RXD
        {GPIOB, GPIO_PIN_8,   NULL,     NO_ADC        , &hTIM4 ,   TIM_CHANNEL_3, 13      },  // 13                 I2C1 SCL
        {GPIOB, GPIO_PIN_9,   NULL,     NO_ADC        , &hTIM4 ,   TIM_CHANNEL_4, 14      },  // 14 LED             I2C1 SDA
        {GPIOA, GPIO_PIN_15,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , 15      },  // 15
        {GPIOB, GPIO_PIN_3,   NULL,     NO_ADC        , NULL   ,   NO_PWM       , 16      },  // 16
        {GPIOB, GPIO_PIN_4,   NULL,     NO_ADC        , NULL   ,   NO_PWM       , 17      },  // 17
        {GPIOB, GPIO_PIN_12,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , 18      },  // 18
        {GPIOB, GPIO_PIN_13,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , 19      },  // 19                 SPI2_SCK
    
        {GPIOB, GPIO_PIN_14,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , 20      },  // 20                 SPI2_MISO
        {GPIOB, GPIO_PIN_15,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , 21      },  // 21                 SPI2_MOSI
        {GPIOC, GPIO_PIN_14,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , 22      },  // 22
        {GPIOC, GPIO_PIN_15,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , 23      },  // 23 USER_BUTTON
        {GPIOB, GPIO_PIN_10,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , 24      },  // 24                 I2C2 SCL    UART3_TXD
        {GPIOB, GPIO_PIN_11,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , 25      },  // 25                 I2C2 SCL    UART3_RXD
    
    
        {GPIOA, GPIO_PIN_13,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , NO_EXTI },  // 26 JTAG SWDIO
        {GPIOA, GPIO_PIN_14,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , NO_EXTI },  // 27 JTAG SWDCLK
        {GPIOB, GPIO_PIN_5,   NULL,     NO_ADC        , NULL   ,   NO_PWM       , NO_EXTI },  // 28 DXL DIR
        {GPIOB, GPIO_PIN_6,   NULL,     NO_ADC        , NULL   ,   NO_PWM       , NO_EXTI },  // 29 DXL TXD
        {GPIOB, GPIO_PIN_7,   NULL,     NO_ADC        , NULL   ,   NO_PWM       , NO_EXTI },  // 30 DXL RXD
    
        {NULL , 0          ,  NULL,     NO_ADC        , NULL   ,   NO_PWM       , NO_EXTI }
    };
    You can see the two sets of pins to use...
    Likewise it looks like they are showing in chip.h:

    Code:
    #define BOARD_SPI1_NSS_PIN      0   //D10 (PA4)
    #define BOARD_SPI1_MOSI_PIN     7   //D11 PA7
    #define BOARD_SPI1_MISO_PIN     6   //D12 PA6
    #define BOARD_SPI1_SCK_PIN      1   //D13 PA5
    #define BOARD_SPI2_NSS_PIN      18  //D26 PB12
    #define BOARD_SPI2_MOSI_PIN     21  //D29 PB15
    #define BOARD_SPI2_MISO_PIN     20  //D28 PB14
    #define BOARD_SPI2_SCK_PIN      19  //D27 PB13
    I believe the code defaults to trying to use SPI1...
    Code:
    SPIClass SPI(SPI1);
    Don't remember what is needed to change to SPI2...
    Maybe you can yourself create an instance the sameway with SP2.

    Or you might be able to use their method changePort.
    Something like SPI.changePort(SPI2);

    Again it has been a long while

  6. #6
    Join Date
    Jun 2013
    Location
    Tucson, AZ
    Posts
    253
    Rep Power
    28

    Re: OpenCM 9.04 and SPI

    I use it on my Mech to communicate with an Arduino Pro Mini on my gun board. Here is the code I use:

    #include <SPI.h>


    // SPI Ports Setup
    // SPI1 Port - Not Used
    SPIClass SPI_1(1);


    // SPI2 Port - Gun Communications
    SPIClass SPI_2(2);




    void setup()
    {
    /* SPI Ports Setup */
    // SPI1 Port - (Not Used)
    SPI_1.beginTransaction(SPISettings(140625, MSBFIRST, SPI_MODE0));


    // SPI2 Port - Gun Communications
    SPI_2.beginTransaction(SPISettings(140625, MSBFIRST, SPI_MODE0));
    }




    Then use
    SPI_2.transfer(x);
    where "x" is the byte to send.


    On the openCM9.04 I only use the SPI to send and don't read anything back. I assume there is an analogous command to "transfer" to read back from the SPI peripheral but haven't looked into it.


    Hope this helps.

  7. #7

    Re: OpenCM 9.04 and SPI

    In the Arduino API, "transfer" returns the byte that came back while it sent the argument byte.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question(s) Dynamixels AX-12A on OpenCM 9.04 + OpenCM 485: how to send instruction packets
    By Daisuke71 in forum DYNAMIXEL & Robot Actuators
    Replies: 5
    Last Post: 05-21-2019, 06:44 PM
  2. OpenCM IDE vs Arduino IDE
    By cod65 in forum DYNAMIXEL & Robot Actuators
    Replies: 4
    Last Post: 03-19-2018, 12:14 PM
  3. OpenCM 9.04 iwdg
    By lpala in forum Arbotix, Microcontrollers, Arduino
    Replies: 0
    Last Post: 07-28-2017, 12:32 PM
  4. OpenCM 9.04, best way to beep?
    By jwatte in forum DYNAMIXEL & Robot Actuators
    Replies: 10
    Last Post: 04-09-2017, 12:11 PM
  5. OpenCM IDE (Ubuntu 14.04)
    By rasheinstein in forum Arbotix, Microcontrollers, Arduino
    Replies: 2
    Last Post: 04-12-2016, 12:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •