Baby-o spi


I’m pretty new around here and just bought bayby-o.
Is there way to use SPI because I got LCD w/ backpack controller which requires SPI communication?

PB3 is tied up with motor I guess.

Are you going to control two motors with your Baby Orangutan?

If you are using two motors, then you definitely can’t use the built-in SPI module because, as you said, the PB3/MOSI line is used for motor control. Also, all three of the SPI lines are used for ISP programming so it would be difficult to use them for something else.

Your LCD device is an SPI slave (not a master), right? If it’s a slave then you can easily do software SPI on any three I/O pins (or two if you don’t need to retrieve data from the LCD). We haven’t written a software SPI library, but it shouldn’t be too hard to do using the Pololu AVR C/C++ library, in particular the Digital I/O functions and delay_us(). You should read the datasheet of your device to find out exactly how the SPI protocol works. Different SPI devices have different conventions about when data is read and when data is written (i.e. rising or falling edge of SCK).

If you write some code and it’s not working, feel free to post it here and we’ll take a look at it. Just be sure to simplify it to the simplest thing that doesn’t work but should, and provide a link to the documentation of your LCD, and provide an explanation of what your code is trying to do.


Hi David

I was trying to use Baby-O for small game with LED matrix which only interface thru SPI.

Hardware SPI would be much nicer than Pseudo/Software SPI, :confused:

Anyway, I was successfully interfacing with my LED.
I put my software SPI snippet here for other’s reference.

#define SCLK 	IO_C3
#define MOSI        IO_C4
#define SS	IO_C5


Software SPI routine

char SPI_SendByte(char out)
    char i;
    char in = 0x00;
    set_digital_output(SCLK, LOW);
    set_digital_output(MOSI, LOW);
    //set_digital_output(SS, LOW); // chip select
    i = 0x80;
              set_digital_output(MOSI, HIGH);	
              set_digital_output(MOSI, LOW);   
         set_digital_output(SCLK, HIGH);
                in |= i;                       
         set_digital_output(SCLK, LOW);
         i >>= 1;
   //set_digital_output(SS, HIGH);
   return in;                        



Thank you for sharing your code. I notice that there are some commented out lines that seem like they should not be commented out (e.g. your 10ms delay). Have you considered using a hardware timer and timer interrupts to send and receive SPI bytes? This approach would take up significantly less of your processing power than the blocking function you posted and would let the rest of your program continue running while the data is being transferred.

Also, though I have no experience with this, apparently you can use the USART on the ATmega328P in SPI mode (with pins XCK, RX, and TX), though I think you are restricted to master-only operation. Please see section 20 of the ATmega328P datasheet for more information. If you do get SPI working using the USART in SPI mode or need help understanding the datasheet, please let us know. This might help others who want to interface Orangutans with SPI slaves.

- Ben