Hey guys,
Continuing on with my project, I'm working on getting the Maple to communicate with the ADS7843 Touch Screen Controller. I've configured SPI:
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);
spi_gpio_cfg(true, GPIOA, 4, GPIOA, 5, 6, 7);
spi_master_enable(SPI1, SPI_BAUD_PCLK_DIV_128, SPI_MODE_0, cfg_flags);
and wrote a simple transfer & read function:
uint8_t SPI_ReceiveByte(uint8_t data)
{
spi_tx(SPI1, &data, 1);
while (!spi_is_rx_nonempty(SPI1));
return (uint8_t)spi_rx_reg(SPI1);
}
All of this was based on what HardwareSPI was doing. Unfortunately, the above doesn't work. Looking at the libmaple spi_master.cpp example I realized that SPI doesn't handle the selecting/deslecting, so I followed what the example did and added:
#define NSS 10
pinMode(NSS, OUTPUT);
delay(100);
digitalWrite(NSS, HIGH);
then to send/read I use:
digitalWrite(NSS, LOW);
spiRecvBuffer[0] = SPI_ReceiveByte(0xD0);
// ....
digitalWrite(NSS, HIGH);
just after the spi init block of code. Unfortunately, now... whenever the Maple receives a few SPI samples, it causes the pin 13 LED to pulsate at 3.7kHz @ ~10% duty. It looks REALLY cool, but not what I was looking for. The moment I comment out the pinMode(NSS, OUTPUT);
line, everything returns back to normal, except the select line stays HIGH -- even though spi_gpio_cfg
was supposed to take care of that for me.
Am I doing something wrong?
-robodude666