cancel
Showing results for 
Search instead for 
Did you mean: 

Problem reading gpio pins in parallel from multiple eeproms.

TSa.1
Associate II

0693W000001qVfmQAE.jpgIm trying to write to and read data from 10 eeproms in parallel. I first transmit the data in parallel to all the eeproms via spi, I then read data in parallel by first transmitting the address of data stored in the eeprom and then transmitting dummy data in non blocking mode in order to pass a clock signal to eeprom and allow it to output data stored.

From the signals on my oscilloscope everything works perfectly, the eeprom outputs data I send it. However when trying to read the gpio pins in order to record data only the first 4 bits in every byte gets read as observed from debug mode.

Attached is my code and relevant pics.

Thanks for your help.

Edit: Solution in last post

0693W000001qVKyQAM.jpg0693W000001qVKjQAM.png

uint8_t data_tx[6]={2,0,0,1,21,1};  //0,1,5,1 is data i send to store
uint8_t address_read[4]={3,0};
uint8_t write_en=6;
uint16_t dat[100];
uint8_t dummy[3]={0,0,0}; 
 
while (1)
  {
		//set write enable latch in parallel
		GPIOA->ODR = 0x0000; // pull the CS pins low
		HAL_SPI_Transmit(&hspi3,&write_en, 1, 10);	//set write enable latch
		GPIOA->ODR = 0xffff;  // pull the CS pins high
		
		HAL_Delay(10);
		
		//write in parallel
		GPIOA->ODR = 0x0000;  // pull the CS pin low
		HAL_SPI_Transmit(&hspi3,data_tx, 6, 10);						 //transmit addresses and data
		GPIOA->ODR = 0xffff;   // pull the CS pins high
		
		HAL_Delay(10);
		
		//read in parallel using ports
		GPIOA->ODR = 0x0000; // pull the CS pins low
		HAL_SPI_Transmit (&hspi3, address_read, 2, 10);  // send address
		HAL_SPI_Transmit_IT(&hspi3, dummy, 20);
		for(int i = 0; i < 100; i++) 
		{	
			if((GPIOB->IDR & 0x01ff) >= 0x01f0) 
			{
				dat[i] = (GPIOB->IDR & 0x01ff) ; //problematic
			}
		}
		GPIOA->ODR = 0xffff;   // pull the CS pins high
		HAL_Delay(10);
  }

13 REPLIES 13

I changed my while loop to this, it doesn't seem to work. Can you please correct me

  while (1)
  {		
		 MX_SPI3_Init();	
 
		//set write enable latch in parallel
		GPIOA->ODR = 0x0000; // pull the CS pins low
		HAL_SPI_Transmit(&hspi3,&write_en, 1, 10);	//set write enable latch
		GPIOA->ODR = 0xffff;  // pull the CS pins high
		
		HAL_Delay(10);
		
		//write in parallel
		GPIOA->ODR = 0x0000;  // pull the CS pin low
		HAL_SPI_Transmit(&hspi3,data_tx, 6, 10);						 //transmit addresses and data
		GPIOA->ODR = 0xffff;   // pull the CS pins high
		
		HAL_Delay(10);
		
		//read in parallel using ports
		GPIOA->ODR = 0x0000; // pull the CS pins low
		HAL_SPI_Transmit (&hspi3, address_read, 2, 10);  // send address
	
		GPIO_InitTypeDef GPIO_InitStruct = {0}; //change SCK to gpio
		GPIO_InitStruct.Pin = GPIO_PIN_10;
		GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
		GPIO_InitStruct.Pull = GPIO_PULLDOWN;
		GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
		HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
	
		for(int i = 0; i < 25; i++) 
		{	
			HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_10);
			if((GPIOC->ODR & 0x0400) == 0x0400) 
			{
				dat[i] = (GPIOB->IDR);
			}
			HAL_Delay(1);
		}
		GPIOA->ODR = 0xffff;   // pull the CS pins high
		
		HAL_Delay(10);
    /* USER CODE BEGIN 3 */
  }

> it doesn't seem to work

What are the symptoms?

Did you observe the pins (SCK and some of the MISO/PBx)?

JW

while (1)
  {
    /* USER CODE END WHILE */
		HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10);
		MX_SPI3_Init();	
 
		//set write enable latch in parallel
		GPIOA->ODR = 0x0000; // pull the CS pins low
		HAL_SPI_Transmit(&hspi3,&write_en, 1, 1);	//set write enable latch
		GPIOA->ODR = 0xffff;  // pull the CS pins high
		
		HAL_Delay(10);
		
		//write in parallel
		GPIOA->ODR = 0x0000;  // pull the CS pin low
		HAL_SPI_Transmit(&hspi3,data_tx, 6, 6);						 //transmit addresses and data
		GPIOA->ODR = 0xffff;   // pull the CS pins high
		
		HAL_Delay(10);
		
		//read in parallel using ports
		GPIOA->ODR = 0x0000; // pull the CS pins low
		HAL_SPI_Transmit(&hspi3, address_read, 2, 2);  // send address
		
		HAL_SPI_DeInit(&hspi3); //deinitialise spi
		
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_10, GPIO_PIN_RESET); //make sck a gpio
		GPIO_InitTypeDef GPIO_InitStruct = {0};
		GPIO_InitStruct.Pin = GPIO_PIN_10;
		GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
		GPIO_InitStruct.Pull = GPIO_NOPULL;
		GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
		HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
	
		for(int i = 0; i < 25; i++) 
		{	
			HAL_GPIO_WritePin(GPIOC, GPIO_PIN_10, GPIO_PIN_SET);
			if((GPIOC->ODR & 0x0400) == 0x0400) 
			{
				dat[i] = ((GPIOB->IDR) & 0x03ff);
			}
			HAL_GPIO_WritePin(GPIOC, GPIO_PIN_10, GPIO_PIN_RESET);
		}
		GPIOA->ODR = 0xffff;   // pull the CS pins high
		
		HAL_Delay(10);
    /* USER CODE BEGIN 3 */
  }

So it works now, I get a correct output on the oscilloscope. However, I dont think im sampling data GPIO correctly:

I transmit 3 bytes: 1,21,1 but this is what I see in debug mode:

What do u think is the issue?

0693W000001qXkeQAE.png

0693W000001qXmuQAE.jpg

Nevermind, this works now! I dont know why it started working all of a sudden