cancel
Showing results for 
Search instead for 
Did you mean: 

Enc424J600 with STM32L431 interface

RKuma.7.302
Associate II

Hello Team,

I need your support to integrate the Enc424J600 ethernet IC with STM32L431, I have enabled the SPI line and trying to communicate with IC but I am not able to read the register value from the Enc424J600 chip.

Ethernet State:

Status led is blinking.

SPI init:

static void MX_SPI2_Init(void)

{

 /* USER CODE BEGIN SPI2_Init 0 */

 /* USER CODE END SPI2_Init 0 */

 /* USER CODE BEGIN SPI2_Init 1 */

 /* USER CODE END SPI2_Init 1 */

 /* SPI2 parameter configuration*/

 hspi2.Instance = SPI2;

 hspi2.Init.Mode = SPI_MODE_MASTER;

 hspi2.Init.Direction = SPI_DIRECTION_2LINES;

 hspi2.Init.DataSize = SPI_DATASIZE_8BIT;

 hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;

 hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;

 hspi2.Init.NSS = SPI_NSS_SOFT;

 hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;

 hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;

 hspi2.Init.TIMode = SPI_TIMODE_DISABLE;

 hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

 hspi2.Init.CRCPolynomial = 7;

 hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;

 hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;

 if (HAL_SPI_Init(&hspi2) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN SPI2_Init 2 */

 /* USER CODE END SPI2_Init 2 */

}

Enc function:

static uint8_t currentBank = 0;

uint8_t TxData[8],RxData[10];

void enc624j600_setBank(uint8_t bank)

{

  if (bank != currentBank)

  {

   HAL_GPIO_WritePin(ETH_SPI_SEL_GPIO_Port, GPIO_PIN_14, GPIO_PIN_RESET);

   TxData[0] = (0b11000000 | (bank<<1));

    HAL_SPI_Transmit(&hspi2,&TxData[0],1,200);

    HAL_GPIO_WritePin(ETH_SPI_SEL_GPIO_Port, GPIO_PIN_14, GPIO_PIN_SET);

    currentBank = bank;

  }

}

void enc624j600SpiWriteRegister8(uint8_t addr, uint8_t value)

{

  if ((addr & regGlobal) == 0)

  {

    enc624j600_setBank(addr >> 5);

  }

  TxData[0] = (1<<6) | (addr & 0b11111);

  TxData[0] = value;

  HAL_GPIO_WritePin(ETH_SPI_SEL_GPIO_Port, GPIO_PIN_14, GPIO_PIN_RESET);

  HAL_SPI_Transmit(&hspi2,&TxData[0],2,200);

  HAL_GPIO_WritePin(ETH_SPI_SEL_GPIO_Port, GPIO_PIN_14, GPIO_PIN_SET);

}

void enc624j600SpiWriteRegister16(uint8_t addr, uint16_t value)

{

  enc624j600SpiWriteRegister8(addr, value & 0xFF);

  enc624j600SpiWriteRegister8(addr+1, value >> 8);

}

uint8_t enc624j600SpiReadRegister8(uint8_t addr)

{

uint8_t dat = 0;

  if ((addr & regGlobal) == 0)

  {

    enc624j600_setBank(addr >> 5);

  }

  

  TxData[0] = (addr & 0b11111);

  TxData[0] = 0;

    HAL_GPIO_WritePin(ETH_SPI_SEL_GPIO_Port, GPIO_PIN_14, GPIO_PIN_RESET);

    HAL_SPI_Transmit(&hspi2,&TxData[0],1,200);

    HAL_SPI_Receive(&hspi2,&RxData[0],1,200);

    //HAL_SPI_TransmitReceive(&hspi2,&TxData[0],RxData,1,200);

    HAL_GPIO_WritePin(ETH_SPI_SEL_GPIO_Port, GPIO_PIN_14, GPIO_PIN_SET);

  return dat;

}

uint16_t enc624j600SpiReadRegister16(uint8_t addr)

{

uint16_t dat = enc624j600SpiReadRegister8(addr)

       | (enc624j600SpiReadRegister8(addr+1) << 8);

printf("%04x\n",dat);

  return dat;

}

void encinit(uint8_t* macaddr)

{

  enc624j600WriteRegister16(EUDAST, 0x1234);

enc624j600ReadRegister16(EUDAST)!=0x1234)

{

enc624j600WriteRegister16(EUDAST, 0x1234);

osDelay(1000);

}

}

Main code:

void StartDefaultTask(void *argument)

{

 /* USER CODE BEGIN 5 */

uint8_t mac[] = {0x23,0x23,0xae,0x24,0x24,0x25};

encinit(mac);

 /* Infinite loop */

 for(;;)

 {

  osDelay(1000);

 }

 /* USER CODE END 5 */ 

}

Enc header data:

Attachment

Output: Trying to read the reset data from enc, receive data: 0000h

Reference :

http://ww1.microchip.com/downloads/en/devicedoc/39935b.pdf

1 REPLY 1
Jack Peacock_2
Senior III

The ENC424J600 uses separate SPI clock edges to read and write. Clock polarity is low (you have it right), but the edge must change between read and write cycles. Writes to the ENC are on the rising (1st) edge, while reads are on the trailing (2nd) edge. You are latching data on the SPI incoming port on the wrong clock edge. That's why you aren't getting valid data.

Also, I don't use the HAL so I'm not aware if the SPI read data register is cleared after every write to the SPI port. If not you will have overrun errors at the start of a read.

The ENC is an old controller but it does work with the STR750, an ARM7TDMI controller and the predecessor to the STM32F1. No reason it shouldn't work with an STM32 as well. Make sure your SPI clock rate doesn't exceed the ENC rating. I usually ran it at about 7.5MHz.

One gotcha you might watch for is configuring automatic 10/100 rate detection in the PHY. There are some problems with early half-duplex 10Mbit switches where the ENC won't detect properly. Reverse ARP (if you use TCP/IP) will fix this. I don't recall if Microchip ever admitted to the issue (they didn't as of 2010, last time I used the ENC).

Jack Peacock