I've got a problem with using I2C2 and SPI2 on STM32F103 MCU. I2C2 before using SPI2 work good, but when I use SPI2, I2C2 stops working. I know that Chibios use DMA to work with this peripherials and I remember to use start() and stop() functions:
Code: Select all
read_and_print_temp_I2C(); //print temperature, good result, any problems
spiStart(&SPID2, &ls_spicfg);
spiStop(&SPID2);
read_and_print_temp_I2C(); //here i've got problems
Code in function read_and_print_temp_I2C() call to transmit function contains i2cMasterTransmitTimeout function.
Temperature sensor -> MCP9800.
I also remeber to read at least 2 bytes from I2C.
Code: Select all
i2cflags_t errors;
msg_t res;
i2cInit();
i2cStart(i2cdrv, i2ccfg);
OPERATION_DELAY;
i2cAcquireBus(i2cdrv);
res = i2cMasterTransmitTimeout(i2cdrv, addr, txbuf, txbytes, rxbuf, rxbytes, timeout);
if (res != RDY_OK) {
if (res == RDY_TIMEOUT) {
error("I2C timeout!");
}
errors = i2cGetErrors(i2cdrv);
if(errors != 0){
error("errors from I2C: %x", errors);
}
}
i2cReleaseBus(i2cdrv);
i2cStop(i2cdrv);
I've got RDY_TIMEOUT in res after this line:
Code: Select all
res = i2cMasterTransmitTimeout(i2cdrv, addr, txbuf, txbytes, rxbuf, rxbytes, timeout);
I used Chibios 2.4.2 for this project. When I comment dmaStreamAllocate function (file os/hal/platforms/STM32/spi_lld.c lines 246-257):
Code: Select all
/*bool_t b;
b = dmaStreamAllocate(spip->dmarx,
STM32_SPI_SPI2_IRQ_PRIORITY,
(stm32_dmaisr_t)spi_lld_serve_rx_interrupt,
(void *)spip);
chDbgAssert(!b, "spi_lld_start(), #3", "stream already allocated");
b = dmaStreamAllocate(spip->dmatx,
STM32_SPI_SPI2_IRQ_PRIORITY,
(stm32_dmaisr_t)spi_lld_serve_tx_interrupt,
(void *)spip);
chDbgAssert(!b, "spi_lld_start(), #4", "stream already allocated");
rccEnableSPI2(FALSE);*/
and dmaStreamSetPeripherial few lines below:
Code: Select all
/* DMA setup.*/
/*dmaStreamSetPeripheral(spip->dmarx, &spip->spi->DR);
dmaStreamSetPeripheral(spip->dmatx, &spip->spi->DR);*/
I2C2 works good with any errors.
So I think there's problem with dmaStreamRelease in spi_lld_stop.
Maybe someone can help me resolve this problem