2020-06-11 04:23 AM
Im 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
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);
}
Solved! Go to Solution.
2020-06-11 10:14 AM
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?
2020-06-11 05:14 AM
Maybe a diagram or sketch of the hardware connection would help us understand, what are you trying to accomplish.
JW
2020-06-11 05:15 AM
Not sure I follow what your code is trying to do.
This loop doesn't send any clock output. Why would the IDR value change from loop to loop?
for(int i = 0; i < 100; i++)
{
if((GPIOB->IDR & 0x01ff) >= 0x01f0)
{
dat[i] = (GPIOB->IDR & 0x01ff) ; //problematic
}
}
2020-06-11 05:21 AM
Tnx for answering,I hope this block dig helps waclawek.jan
2020-06-11 05:23 AM
Tnx for answering TDK
Well HAL_SPI_Transmit_IT(&hspi3, dummy, 20); transmits dummy data (just 0), so essentially it only passes a clock to the eeproms. Since the previous line of code HAL_SPI_Transmit (&hspi3, address_read, 2, 10); requests eeprom to send data from the particular access as soon as it receives the clock it begins outputting data. Each eeprom outputs darta to its respective gpio pin
2020-06-11 05:26 AM
IDR value doesnt change from loop to loop it just doesnt record data after the first 4 bits (from LSB) of a byte
2020-06-11 05:27 AM
Instead of calling HAL_SPI_Transmit_IT, you should be toggling SCK manually and then reading GPIOB on each cycle. You have no delays in your loop and no method to ensure each call is at the right time with respect to the SCK line state.
2020-06-11 05:29 AM
Thats a good suggestion, I wasnt able to find out how to toggle sck manually. How do you go about this?
2020-06-11 05:37 AM
2020-06-11 05:39 AM
Alright, i'll give that a shot! Thannk you for your help