Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // --- ARDUINO CODE ---
- void loop() {
- digitalWrite(4, 0); // Clear EXTI11 line.
- if (mySerial.available() && received < 480) { // STM32 sending data and is not done.
- buff[received] = mySerial.read(); // Append received data to the buffer.
- received++;
- }
- if (received >= 480) { // If the buffer is full
- received = 0; // transmit it to PC.
- Serial.println(buff);
- }
- if (Serial.available()) {
- if (Serial.read() == 'r') { // PC requests data from the STM32
- digitalWrite(4, 1); // Triggers STM32 EXTI11 line.
- while (Serial.available()) // Empty the buffer.
- Serial.read();
- }
- }
- }
- // --- ---------- ---
- // --- STM32 CODE ---
- void EXTI15_10_IRQHandler(void)
- {
- // Make sure that the interrupt is the good one.
- if (HAL_GPIO_ReadPin(data_req_IRQ_GPIO_Port, data_req_IRQ_Pin)) {
- if (is_sending_data == FALSE) // If no transmission is happening
- should_send_data = TRUE; // raise transmission flag.
- }
- // IRQ handling stuff...
- }
- void HAL_UART_TxCpltCallback(UART_HandleTypeDef * huart) {
- is_sending_data = FALSE; // Transmition is completed, unblock requests.
- }
- void main(void){
- // Init and other stuff...
- while (1) {
- if (should_send_data == TRUE) { // If data was requested
- HAL_GPIO_WritePin(LD5_GPIO_Port, LD5_Pin, GPIO_PIN_RESET);
- HAL_UART_Transmit_IT(&huart3, matrice, 480); // Start transmission by interrupt.
- is_sending_data = TRUE; // Block requests.
- should_send_data = FALSE; // Clear flag.
- }
- // matrice acquisition stuff here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement