Hi,
I'm using TM4C123G for sending commands through SPI to a Semtech SX1272 transceiver. I've tried almost everything, but nothing works. It seems that SX1272 does not receive anything. I post my code here in case I'm doing sth wrong with TM4C123G.
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/ssi.h"
#include "driverlib/sysctl.h"
#define NUM_BYTES_SSI 2
int main(void) {
uint32_t pui32DataTx1 [NUM_BYTES_SSI];
uint32_t pui32DataTx2 [NUM_BYTES_SSI];
uint32_t pui32DataTx3 [NUM_BYTES_SSI];
uint32_t pui32DataTx4 [NUM_BYTES_SSI];
uint32_t pui32DataTx5 [NUM_BYTES_SSI];
uint32_t pui32DataRx [NUM_BYTES_SSI];
uint32_t ui32Index, i, k;
uint32_t TS_OSC=250*16/3;
uint32_t TS_FS=60*16/3;
uint32_t TS_TR=120*16/3;
uint8_t ui8LED=2;
SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3)
SysCtlClockSet (SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable (SYSCTL_PERIPH_SSI0);
SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure (GPIO_PA2_SSI0CLK);
GPIOPinConfigure (GPIO_PA3_SSI0FSS);
GPIOPinConfigure (GPIO_PA4_SSI0RX);
GPIOPinConfigure (GPIO_PA5_SSI0TX);
GPIOPinTypeSSI (GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2);
SSIConfigSetExpClk (SSI0_BASE, SysCtlClockGet (), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 1000000, 8);
SSIEnable (SSI0_BASE);
while (SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx[0]))
{
}
/////Simple FSK Tx/////
pui32DataTx1[0]=0x81; //RegOpMode (w)
pui32DataTx1[1]=0x00; //Sleep
pui32DataTx2[0]=0x81; //RegOpMode (w)
pui32DataTx2[1]=0x01; //Stdby
pui32DataTx3[0]=0x81; //RegOpMode (w)
pui32DataTx3[1]=0x02; //FSTx
pui32DataTx4[0]=0x81; //RegOpMode (w)
pui32DataTx4[1]=0x03; //Tx
for (ui32Index=0; ui32Index<NUM_BYTES_SSI; ui32Index++)
{
SSIDataPut (SSI0_BASE, 0xFF);
SSIDataPut (SSI0_BASE, pui32DataTx1[ui32Index]);
}
while (SSIBusy(SSI0_BASE))
{
}
SysCtlDelay(TS_OSC);
for (ui32Index=0; ui32Index<NUM_BYTES_SSI; ui32Index++)
{
SSIDataPut (SSI0_BASE, 0xFF);
SSIDataPut (SSI0_BASE, pui32DataTx2[ui32Index]);
}
while (SSIBusy(SSI0_BASE))
{
}
SysCtlDelay(TS_OSC+TS_FS);
for (ui32Index=0; ui32Index<NUM_BYTES_SSI; ui32Index++)
{
SSIDataPut (SSI0_BASE, 0xFF);
SSIDataPut (SSI0_BASE, pui32DataTx3[ui32Index]);
}
while (SSIBusy(SSI0_BASE))
{
}
SysCtlDelay(TS_OSC+TS_FS+TS_TR);
for (ui32Index=0; ui32Index<NUM_BYTES_SSI; ui32Index++)
{
SSIDataPut (SSI0_BASE, 0xFF);
SSIDataPut (SSI0_BASE, pui32DataTx4[ui32Index]);
}
while (SSIBusy(SSI0_BASE))
{
}
SysCtlDelay(TS_OSC+TS_FS+TS_TR);
for (i=0; i<3; i++)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, ui8LED);
// Delay for a bit
SysCtlDelay(2000000);
//SysCtlDelay(3000000*16/3);
// Cycle through Red, Green and Blue LEDs
if (ui8LED == 8)
{
ui8LED = 2;
}
else
{
ui8LED = ui8LED*2;
}
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 5);
}
for (ui32Index=0; ui32Index<NUM_BYTES_SSI; ui32Index++)
{
SSIDataPut (SSI0_BASE, 0xFF);
SSIDataGet (SSI0_BASE, &pui32DataRx[ui32Index]);
}
return 0;
}
Thanks in advance,
Alberto