we are trying to achieve the communication between spi and wiznet w5500 tool, it was compiling properly but when we run it was not responding properly.
i am attaching the code snippet below.are we doing it properly or do we need anything extra?we are not able to ping the IP address also. looking forward for your quick response.
void SPI_Send(uint16_t addr, uint32_t data)
{
uint32_t dataAux;
SSIDataPut(SSI1_BASE, WIZNET_WRITE_OPCODE);
SSIDataPut(SSI1_BASE, addr >> 8 );
SSIDataPut(SSI1_BASE, addr & 0x0FF);
SSIDataPut(SSI1_BASE, data);
while(SSIBusy(SSI1_BASE));
while( SSIDataGetNonBlocking(SSI1_BASE, &dataAux) > 0);
}
uint32_t SPI_Read(uint32_t addr)
{
uint32_t dataAux;
SSIDataPut(SSI1_BASE, WIZNET_READ_OPCODE);
SSIDataPut(SSI1_BASE, addr >> 8 );
SSIDataPut(SSI1_BASE, addr & 0x0FF);
SSIDataPut(SSI1_BASE, 0x00);
while(SSIBusy(SSI1_BASE));
while( SSIDataGetNonBlocking(SSI1_BASE, &dataAux) > 0);
return dataAux;
}
void TCPIntHandler(void)
{
SysCtlDelay(550);
if(SPI_Read(S0_IR) & 0x4) SPI_Send(S0_CR,0x40);
SPI_Send(S0_IR, 0); // Clear Interrupt Register
GPIOIntClear(GPIO_PORTF_BASE, GPIO_INT_PIN_2);
}
void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++);
}
}
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);//check for free port
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //for tcp interrupt
GPIOPinConfigure(GPIO_PD0_SSI1CLK);
GPIOPinConfigure(GPIO_PD1_SSI1FSS);
GPIOPinConfigure(GPIO_PD2_SSI1RX);
GPIOPinConfigure(GPIO_PD3_SSI1TX);
GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_3 | GPIO_PIN_2 |
GPIO_PIN_1 | GPIO_PIN_0);
SSIConfigSetExpClk(SSI1_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_3,
SSI_MODE_MASTER, 1000000, 8);//check for mode
compatibility 16/8//original mode3
SSIEnable(SSI1_BASE);
//
//Ethernet adapter config
//
unsigned char mac_addr[] = {0x00,0x16,0x36,0xDE,0x58,0xF6};
unsigned char ip_addr[] = {192,168,1,10};//10
unsigned char sub_mask[] = {255,255,255,0};
unsigned char gtw_addr[] = {192,168,1,100}; //100
//
// Basic IP configuration
//
SPI_Send(MR,0x80); //Reset
SysCtlDelay( SysCtlClockGet() / 1000 );
//Gateway Address config
SPI_Send(GAR+0,gtw_addr[0]);
SPI_Send(GAR+1,gtw_addr[1]);
SPI_Send(GAR+2,gtw_addr[2]);
SPI_Send(GAR+3,gtw_addr[3]);
//MAC Address config
SPI_Send(SAR+0,mac_addr[0]);
SPI_Send(SAR+1,mac_addr[1]);
SPI_Send(SAR+2,mac_addr[2]);
SPI_Send(SAR+3,mac_addr[3]);
SPI_Send(SAR+4,mac_addr[4]);
SPI_Send(SAR+5,mac_addr[5]);
//Sub Mask config
SPI_Send(SUBR+0,sub_mask[0]);
SPI_Send(SUBR+1,sub_mask[1]);
SPI_Send(SUBR+2,sub_mask[2]);
SPI_Send(SUBR+3,sub_mask[3]);
//Ip config
SPI_Send(SIPR+0,ip_addr[0]);
SPI_Send(SIPR+1,ip_addr[1]);
SPI_Send(SIPR+2,ip_addr[2]);
SPI_Send(SIPR+3,ip_addr[3]);
// Setting the Wiznet W5100 RX and TX Memory Size, we use 2KB for Rx/Tx 4 channels
SPI_Send(RMSR,0x55);
SPI_Send(TMSR,0x55);
//
// Configure Socket 0 as TCP Server
//
SPI_Send(S0_MR, MR_TCP); //TCP Mode activation
SPI_Send(S0_PORT, 0x11); //Using port 4500 = 0x1194
SPI_Send(S0_PORT+1, 0x94);
SPI_Send(IMR,1); //Enable Socket 0 Interrupts only
SPI_Send(S0_CR, CR_CLOSE);
SPI_Send(S0_CR, CR_OPEN);
while(SPI_Read(S0_CR)); //Wait for socket init
SPI_Send(S0_CR, CR_LISTEN);
while(SPI_Read(S0_CR));
//
// Configure and enable Interrupts.
//
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_2);
GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_LOW_LEVEL);
GPIOIntClear(GPIO_PORTF_BASE, GPIO_INT_PIN_2);
IntEnable(INT_GPIOF);
GPIOIntEnable(GPIO_PORTF_BASE, GPIO_INT_PIN_2);
ROM_IntMasterEnable();
//
// Loop forever echoing data through the UART.
//
while(1)
{
n = SPI_Read(S0_SR);
status = SPI_Read(S0_IR);
}