cancel
Showing results for 
Search instead for 
Did you mean: 

Spi communication with MAX22192 SPI IO expander and STM32 ncleoG474RE

sarun
Associate III

HI community,

I got my hands on a MAX22192 evaluation kit (SPI GPIO expander) , currently attempting to communicate with it. While I can receive the input status from the IC, it doesn't respond to the commands I'm sending to it through NUCLEO G474RE.

The evaluation kit includes a USB dongle with its own GUI interface, which I used to capture the waveform.

My SPI is clocked at 2.5 MHz, and the IC supports speeds up to 12 MHz."

Communication with Nucleo G474RE (Getting input status but unresponsive to commands)@2.5Mhz

stm32_data.jpg

Communication data with evaluation kit usb dongle (which works perfectly fine)@5Mhz

image.png

As per the datasheet this is my read and write packet structure

sarun_2-1718785588443.png

according to led matrix register iam trying to setl led at index 0 and in the frame 2 iam trying to readback the status 

image.png

this is my code

 

 

int main(void) {

	/* USER CODE BEGIN 1 */

	/* USER CODE END 1 */

	/* MCU Configuration--------------------------------------------------------*/

	/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
	HAL_Init();

	/* USER CODE BEGIN Init */

	/* USER CODE END Init */

	/* Configure the system clock */
	SystemClock_Config();

	/* USER CODE BEGIN SysInit */

	/* USER CODE END SysInit */

	/* Initialize all configured peripherals */
	MX_GPIO_Init();
	MX_SPI1_Init();
	MX_TIM2_Init();
	MX_LPUART1_UART_Init();
	/* USER CODE BEGIN 2 */
	uint8_t tx_buff[2] = { 0 };
	tx_buff[0] = 0xA0;//led matrix register+msb=1 for write cmd
	tx_buff[1] = 0x01;//set the first led
	uint16_t rx_buff = 0;
	uint8_t status = 0;
	HAL_TIM_Base_Start(&htim2);
	/* USER CODE END 2 */

	/* Infinite loop */
	/* USER CODE BEGIN WHILE */
	while (1) {
		if (switch_status) {
			switch_status = 0;
#define debug_mode0
#ifdef debug_mode0
			GPIOB->BSRR |= (1 << 22); //Reset PB6
			status = HAL_SPI_TransmitReceive(&hspi1, tx_buff, &rx_buff,
					sizeof(tx_buff), 100); //send cmnd to turn on the led
//			printf("%d\n", rx_buff);
			tx_buff[0] = 0x20;//msb=0(read)+register address 7bit
			tx_buff[1] = 0x00;//dummy data
			GPIOB->BSRR |= (1 << 6); //Set PB6
			delay_us(1);//cs high time toprocess data
			GPIOB->BSRR |= (1 << 22); //Reset PB6
			status = HAL_SPI_TransmitReceive(&hspi1, tx_buff, &rx_buff,
					sizeof(tx_buff), 100); //read_cmnd status
			GPIOB->BSRR |= (1 << 6); //Set PB6
			printf("%d\n", rx_buff);//now buffer should contain led status
#elif debug_mode1
			GPIOB->BSRR |= (1 << 22);
			status = HAL_SPI_Transmit(&hspi1, tx_buff, sizeof(tx_buff), 1000); //send data to slave
			GPIOB->BSRR |= (1 << 6);
			for (int i = 0; i < 8; i++) {
				printf("%d ", (rx_buff >> i & 1) ? 1 : 0);

			}
			printf("\ndata=%d\n", rx_buff);
#endif
//			delay_us(500000);
		}

		/* USER CODE END WHILE */

		/* USER CODE BEGIN 3 */
	}
	/* USER CODE END 3 */
}

 

 

Am I missing something related to timing, these are the timing data given in the max22192 data sheet

image.pngimage.png

image.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
sarun
Associate III

Got it sorted out, grounding issues.

View solution in original post

1 REPLY 1
sarun
Associate III

Got it sorted out, grounding issues.