реклама на сайте
подробности

 
 
 
Reply to this topicStart new topic
> не работает ответ i2c от stm32 в режиме slave, HAL
Метценгерштейн
сообщение Jun 2 2016, 13:20
Сообщение #1


Профессионал
*****

Группа: Свой
Сообщений: 1 357
Регистрация: 12-04-05
Из: Петербург
Пользователь №: 4 079



Коллеги, подскажите, как запустить корректно?

Проц STM32F030R8T6

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

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

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

Go to the top of the page
 
+Quote Post
golf2109
сообщение Jun 3 2016, 21:22
Сообщение #2


Участник
*

Группа: Участник
Сообщений: 66
Регистрация: 15-04-10
Из: Kiev
Пользователь №: 56 654



я бы использовал 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)
Go to the top of the page
 
+Quote Post
x893
сообщение Jun 3 2016, 21:31
Сообщение #3


Профессионал
*****

Группа: Свой
Сообщений: 1 333
Регистрация: 27-10-08
Из: Планета Земля
Пользователь №: 41 226



Я бы взял пример от ST и посмотрел на код.
Go to the top of the page
 
+Quote Post
segment
сообщение Jun 4 2016, 10:32
Сообщение #4


Местный
***

Группа: Участник
Сообщений: 352
Регистрация: 10-08-06
Из: Санкт-Петербург
Пользователь №: 19 471



Я бы посмотрел в reference manual
Go to the top of the page
 
+Quote Post
Lagman
сообщение Jun 4 2016, 16:33
Сообщение #5


Знающий
****

Группа: Свой
Сообщений: 875
Регистрация: 28-10-05
Пользователь №: 10 245



В примерах такая последовательность указана
Код
  /*##-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();    
  }
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 29th July 2025 - 19:08
Рейтинг@Mail.ru


Страница сгенерированна за 0.01373 секунд с 7
ELECTRONIX ©2004-2016