Can you guys post code of how you're setting up SPI and using it?
Keep in mind that, while libmaple will setup NSS for you, you must still manually toggle it (at least it did when I used SPI on a Maple last).
I have made this little helper for my projects a while ago:
SPIHelper.c
#include <stdint.h>
#include "wirish.h"
#include "SPIHelper.h"
// SPI1 Pin Defines
#define SCK_PIN 5
#define MISO_PIN 6
#define MOSI_PIN 7
static bool spi1_initalized = false;
void SPI1_Init()
{
if(spi1_initalized == true) return;
uint32 cfg_flags = SPI_FRAME_MSB | SPI_DFF_8_BIT | SPI_SW_SLAVE | SPI_SOFT_SS;
timer_set_mode(TIMER3, TIMER_CH1, TIMER_DISABLED);
timer_set_mode(TIMER3, TIMER_CH2, TIMER_DISABLED);
spi_init(SPI1);
gpio_set_mode(GPIOA, 4, GPIO_AF_OUTPUT_PP);
gpio_set_mode(GPIOA, SCK_PIN, GPIO_AF_OUTPUT_PP);
gpio_set_mode(GPIOA, MISO_PIN, GPIO_INPUT_FLOATING);
gpio_set_mode(GPIOA, MOSI_PIN, GPIO_AF_OUTPUT_PP);
spi_master_enable(SPI1, SPI_BAUD_PCLK_DIV_256, SPI_MODE_0, cfg_flags);
spi1_initalized = true;
#ifdef USBDEBUG
SerialUSB.println("SPI1 Enabled.");
#endif
}
uint8_t SPI1_Receive(uint8_t data)
{
spi_tx(SPI1, &data, 1);
while (!spi_is_rx_nonempty(SPI1));
return (uint8_t)spi_rx_reg(SPI1);
}
void SPI1_Send(uint8_t *data, uint16_t len)
{
while(len--)
SPI1_Receive(*data++);
}
void SPI1_Send(uint8_t data)
{
SPI1_Receive(data);
}
SPIHelper.h
#ifndef __SPIHelper_H__
#define __SPIHelper_H__
void SPI1_Init();
uint8_t SPI1_Receive(uint8_t data);
void SPI1_Send(uint8_t *data, uint16_t len);
void SPI1_Send(uint8_t data);
#define SPI_SetupNSS(gpio, pin) gpio_set_mode(gpio, pin, GPIO_OUTPUT_PP)
#define SPI_SelectLow(gpio, pin) gpio->regs->BRR = (1 << pin)
#define SPI_SelectHigh(gpio, pin) gpio->regs->BSRR = (1 << pin)
#endif
With usage:
#define SPI_PORT GPIOA
#define SPI_NSS 4
SPI1_Init();
SPI_SetupNSS(SPI_PORT, SPI_NSS);
I know it ends up being redundant, as libmaple and wirish have similar functionality... but for some reason I decided mine was better a year or more ago when I wrote the above code... Don't remember now, lol.
The above can easily adapted to support SPI1 and SPI2 if need-be. Alternatively, it can be used to compare between what you're doing... I know mine works, and has worked in SPI2 (though I don't have that snippet available :( Booo HDD failures).
-robodude666