Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: не работает ответ i2c от stm32 в режиме slave
Форум разработчиков электроники ELECTRONIX.ru > Микроконтроллеры (MCs) > ARM
Метценгерштейн
Коллеги, подскажите, как запустить корректно?

Проц STM32F030R8T6

если делать на прерываниях на HAL, то
Код
while (HAL_I2C_Slave_Transmit_IT( &hi2c1, TxBuf, (sizeof(TxBuf)/sizeof(TxBuf[0])) ) != HAL_OK)
    ;

так я отлично принимаю от мастера данные.

Если мастер меня запрашивает что- то, то как мне ему выдать данные? Как только что-то пытаюсь передать или просто, или на прерываниях, сразу шина зависает. И последующая запись идет с write filed.

golf2109
я бы использовал DMA

**
* @brief Transmit in slave mode an amount of data in non-blocking mode with DMA
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
* the configuration information for the specified I2C.
* @param pData Pointer to data buffer
* @param Size Amount of data to be sent
* @retval HAL status
*/
HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size)
x893
Я бы взял пример от ST и посмотрел на код.
segment
Я бы посмотрел в reference manual
Lagman
В примерах такая последовательность указана
Код
  /*##-2- Put I2C peripheral in reception process ###########################*/  
  if(HAL_I2C_Slave_Receive_IT(&I2cHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
  {
    /* Transfer error in transmission process */
    Error_Handler();        
  }
  
  /*##-3- Wait for the end of the transfer ###################################*/  
  /*  Before starting a new communication transfer, you need to check the current  
      state of the peripheral; if it’s busy you need to wait for the end of current
      transfer before starting a new one.
      For simplicity reasons, this example is just waiting till the end of the
      transfer, but application may perform other tasks while transfer operation
      is ongoing. */  
  while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY)
  {
  }

  /*##-4- Start the transmission process #####################################*/  
  /* While the I2C in reception process, user can transmit data through
     "aTxBuffer" buffer */
  if(HAL_I2C_Slave_Transmit_IT(&I2cHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK)
  {
    /* Transfer error in transmission process */
    Error_Handler();    
  }
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Invision Power Board © 2001-2025 Invision Power Services, Inc.