SPI Development
Page 1 of 1

Author:  Mikeloto [ Mon Dec 28, 2015 10:28 pm ]
Post subject:  SPI Development

Based on sample of Mr. Pito from RetroBSD i make simple test for the spi
on the Whitecat X1 we have two free spi spi2 and spi4 I used spi4 for the test

spi1 at pins sdi=RD2/sdo=RD3/sck=RD1
spi2 at pins sdi=RG7/sdo=RG8/sck=RG6
spi3 at pins sdi=RB10/sdo=RB9/sck=RB14
spi4 at pins sdi=RD11/sdo=RD0/sck=RD10

This is the code I placed 16Mhz and use saleae analizer but not activity on the spi. I think code is correct.....

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/spi.h>

static int spi;                         // SPI driver descriptor
#define SPI_DEVNAME         "/dev/spi4" // analizer connected here
#define SPI_KHZ             16000       // Clock speed 16 MHz
#define SPI_SELPIN          0x0049      // select pin RD9

int main(){

        int i = 0;
        spi = open (SPI_DEVNAME, O_RDWR);
        if (spi < 0) {
                perror (SPI_DEVNAME);
                exit (-1);

//      ioctl (spi, SPICTL_SETMODE, 0);
        ioctl (spi, SPICTL_SETRATE, SPI_KHZ);
        ioctl (spi, SPICTL_SETSELPIN, SPI_SELPIN);

        while(i < 100) {
                ioctl (spi, SPICTL_IO8(1), 0xff);


The idea is to implement code to use this LoRa module

Author:  Pito [ Wed Dec 30, 2015 8:21 pm ]
Post subject:  Re: SPI Development

Did you enable the spi4 in the board config?
You have to recompile and reflash the kernel.
That is not easy however.
Easy way is you delete your_board directory in "../LiteBSD/sys/compile/your_board" and run "bmake kernel" from top.
You will get your board's directory back. Reflash the vmunix.hex from the board's dir then.
Doublecheck the timestamp of the vmunix.hex, must be the latest after the kernel build.

Interesting chip, indeed:
The SX1276/77/78/79 transceivers feature the LoRa® long range modem that provides ultra-long range spread spectrum communication and high interference immunity whilst minimizing current consumption.
Any experience with it?

Author:  Mikeloto [ Wed Dec 30, 2015 10:27 pm ]
Post subject:  Re: SPI Development

Pito wrote:
Did you enable the spi4 in the board config?
You have to recompile and reflash the kernel.

Yes Pito, was enabled you can look at the top of the first post this message comes from the boot...

Sure it will works sd card it's working (also fine at 25Mbit/sec) then I hope the driver too is ok, will look maybe to the driver itself when have a little time....

We got some modules from Microchip RN2483 inside pic18lf46k22 with SX1276 we need to manage power consumption and we are developing some nodes with LF series and sleep all the time.

On the microchip nanowatt XLP calculator does not appear PIC32 series why :lol: :lol: :lol: ??

They are projects for the comming year at the moment on the development stage, looking for old cheap GSM big antennas will be interesting too, hope will increase the range and works fine....

The good thing will be when be available in small quantity the SX1301 or out of the LoRa® Alliance members, then make LiteBSD LoRa® gateway will be nice due to small traffic, etc....

Cheers Pito and Merry Christmas and Happy New Year !!

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group