Hello, what im trying to do is reverse engineering unknown device. What i need is catch a 16bytes data from it. Each clk's pulse speed is about 20 nanoseconds. I'm using stm32f4 discovery board, so i should be able to catch it as stm32 powerful uC. The fact that im really new in Keil, and i dont know if im doing it a propper way, for example to detect a GPIO goes down, im using this code
while (HAL_GPIO_ReadPin (GPIOC,GPIO_PIN_7) == 0){}
Is it proper way to do it? THe whole code with comments are:
while (1) { uint8_t collect_bits = 0; char string_array[21] = {0}; // HAL_Delay(200); while (HAL_GPIO_ReadPin (GPIOC,GPIO_PIN_9) == 0){} // wait until GPIOC 9 goes high while (HAL_GPIO_ReadPin (GPIOC,GPIO_PIN_9) == 1){} // wait until GPIOC 9 goes low for (int i = 0; i < 8; i++) // make a loop for reading byte { while (HAL_GPIO_ReadPin (GPIOC,GPIO_PIN_7) == 0){} // wait until clock goes high int32_t current_bit = HAL_GPIO_ReadPin (GPIOC,GPIO_PIN_9); // READ bit on PINC 9 collect_bits |= current_bit << i; // Shift current_bit to position i and // put it into collect_bits using bit wise OR while (HAL_GPIO_ReadPin (GPIOC,GPIO_PIN_7) == 1){} // wait until clock goes low, then repeat while loop untill we collect 8 bits } sprintf(string_array, "%X", collect_bits); // just simple convertation for PC output CDC_Transmit_FS((uint8_t*)string_array, sizeof(string_array)); // print result. // //break; /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
The problem is that output is not correct.What am i doing wrong? thanks
Thanks for reply Hans-Bernhard Broeker, Strange, OneDrive works for me. I uploaded to imgur, i hope this ok :) https://imgur.com/a/prxkKoC https://imgur.com/a/Eko6Svc ( SEE THIS IMAGE MY OSCILO SHOWS DATA IT BEGINS FROM FE 00 10 etc (SPI PROTOCOL)) https://imgur.com/a/95AkqGl ( The begining of package, from here i want to read) I took a slower device which has 1.5 microseocnds pulses in purpose to debugg with slower clock speed. And yes the first one was around 50 nanoseconds ( not 20, my mistake). My oscilloscope catching this data as SPI( it catches data with clock and decode it to hex value, as you can see in images, the data is correct). As i understand if cs is low( i pulled it down as hardware not soft), the slave will receive messages, yes maybe it will not be correct cuz of wrong timings but it will receive something, and now it doesnt receive at all, my buffer dont change. Even if just loop HAL_SPI RECEIVE function it will not read anything.