spiStartExchange() causes port_halt()
Posted: Mon Sep 02, 2013 1:23 pm
Hi,
I am trying to send some strings over SPI but have problems with the port_halt() lock.
I am using an STM32F103 on SPI 1
Here is the code I am using
I tracked the communication with the logic analyzer and I can see, that all the 5 (3) Bytes are send out by the driver, but the CS line is not been released.
If I halt the debuger, the pointer is in the port_halt() function and the dbg_panic_msg says "spiUnselect(), #1", dbg_isr_cnt "not within ISR" and dbg_lock_cnt "within lock".
But if I uncomment the second spiStartExchange() part, the dbg_panic_msg says "spiStartExchange, #1", so it seems to be a problem with the first spiStartExchange Function as the second is never reached and the CS Line stays low.
What I am doing wrong?!
Best regards
Stomper
I am trying to send some strings over SPI but have problems with the port_halt() lock.
I am using an STM32F103 on SPI 1
Here is the code I am using
Code: Select all
#include "ch.h"
#include "hal.h"
#include "test.h"
/*
* Red LED blinker thread, times are in milliseconds.
*/
static WORKING_AREA(waThread1, 128);
static msg_t Thread1(void *arg) {
(void)arg;
chRegSetThreadName("blinker");
while (TRUE) {
palClearPad(GPIOB, GPIOB_LED3);
chThdSleepMilliseconds(500);
palSetPad(GPIOB, GPIOB_LED3);
chThdSleepMilliseconds(500);
}
}
/*
* SPI configuration structure.
*/
static const SPIConfig spicfg_Acc = {
NULL,
/* HW dependent part.*/
GPIOB, // Chip Select Port
GPIOB_CSAcc, // Chip Select Pin
(SPI_CR1_MSTR | SPI_CR1_BR_0 |SPI_CR1_BR_2 | SPI_CR1_CPOL ) // MasterMode, Baudratebits
};
/*
* Application entry point.
*/
int main(void) {
// Read/Write + Adress + 2x Dummy Byte
uint8_t SPIOut1[5] = {0x80, 0x77,0xB3, 0xFF, 0xFF};
uint8_t SPIOut2[3] = {0xB3, 0xFF, 0xFF};
uint8_t SPIIn[3] = {0,0,0};
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
spiStart(&SPID1, &spicfg_Acc);
spiSelect(&SPID1);
spiStartExchange(&SPID1, 5, SPIOut1, SPIIn);
//spiStartExchange(&SPID1, 3, SPIOut2, SPIIn);
spiUnselect(&SPID1);
/*
* Creates the blinker thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state.
*/
while (TRUE) {
chThdSleepMilliseconds(500);
}
}
I tracked the communication with the logic analyzer and I can see, that all the 5 (3) Bytes are send out by the driver, but the CS line is not been released.
If I halt the debuger, the pointer is in the port_halt() function and the dbg_panic_msg says "spiUnselect(), #1", dbg_isr_cnt "not within ISR" and dbg_lock_cnt "within lock".
But if I uncomment the second spiStartExchange() part, the dbg_panic_msg says "spiStartExchange, #1", so it seems to be a problem with the first spiStartExchange Function as the second is never reached and the CS Line stays low.
What I am doing wrong?!
Best regards
Stomper