diff --git a/Src/dw1000.c b/Src/dw1000.c
index f2e5f58ae3fe6873c545d316df3a54366fac7ec8..3fe78b4ad3787ad78fc1e53fd7ae668de3f3cfd4 100644
--- a/Src/dw1000.c
+++ b/Src/dw1000.c
@@ -38,6 +38,9 @@ int dw1000_sendFrame(uint8_t *payload, uint16_t len) {
 	// set up a complete config for the register
 	// the bits are cleared automatically after the transmission and need to be set up for the next transmission again!
 	uint32_t sys_ctrl = 0;
+	sys_ctrl |= SYS_CTRL_TRXOFF;							//  Immediately cancel all RX and TX operations, bring radio to IDLE state
+	dw1000Hal_writeRegister(SYS_CTRL_ID, &sys_ctrl, 4);
+	sys_ctrl = 0;
 
 															// SFCST not set -> automatic CRC calculation
 	sys_ctrl |= SYS_CTRL_TXSTRT;							// start transmission
@@ -57,9 +60,9 @@ int dw1000_sendFrame(uint8_t *payload, uint16_t len) {
 	// check for TXFRS bit set
 	uint32_t sys_status = 0;
 
-	do {
-		dw1000Hal_readRegister(SYS_STATUS_ID, &sys_status, 4);
-	} while (!(sys_status & SYS_STATUS_TXFRS));
+	//do {
+	//	dw1000Hal_readRegister(SYS_STATUS_ID, &sys_status, 4);
+	//} while (!(sys_status & SYS_STATUS_TXFRS));
 
 	// return status
 	return 0;
diff --git a/Src/dw1000_hal.c b/Src/dw1000_hal.c
index a6292a8569a8dd3fc22694a8f9b40a0a63faf9f3..1542cdf5d523b29dd3909c631c46780c9aff4299 100644
--- a/Src/dw1000_hal.c
+++ b/Src/dw1000_hal.c
@@ -46,6 +46,7 @@ int dw1000Hal_readSubRegister(uint8_t regID, uint16_t offset, uint8_t *dest, uin
 {
 	uint8_t dummy[3];
 	int ret;
+	portENTER_CRITICAL();
 	if ((spiSema != NULL) && (xSemaphoreTake(spiSema, ( TickType_t ) DW1000HAL_SPI_TIMEOUT) == pdTRUE)) {
 		if (len <= 127) {
 			dummy[0] = regID & 0x3f; //set the first two bit 0 (read access, no subregister)
@@ -70,6 +71,7 @@ int dw1000Hal_readSubRegister(uint8_t regID, uint16_t offset, uint8_t *dest, uin
 	} else {
 		ret = HAL_LOCKED;
 	}
+	portEXIT_CRITICAL();
 	return ret;
 }
 
@@ -77,6 +79,7 @@ int dw1000Hal_writeSubRegister(uint8_t regID, uint16_t offset, uint8_t *src, uin
 {
 	uint8_t dummy[3];
 	int ret;
+	portENTER_CRITICAL();
 	if ((spiSema != NULL) && (xSemaphoreTake(spiSema, ( TickType_t ) DW1000HAL_SPI_TIMEOUT) == pdTRUE)) {
 		if (len <= 127) {
 			dummy[0] = regID & 0x3f; //set the first two bit 0 (read access, no subregister)
@@ -102,6 +105,7 @@ int dw1000Hal_writeSubRegister(uint8_t regID, uint16_t offset, uint8_t *src, uin
 	} else {
 		ret = HAL_LOCKED;
 	}
+	portEXIT_CRITICAL();
 	return ret;
 }
 
@@ -110,7 +114,8 @@ int dw1000Hal_readRegister(uint8_t regID, uint8_t *dest, uint16_t len)
 	uint8_t dummy;
 	dummy = regID & 0x3f; //set the first two bit 0 (read access, no subregister)
 	int ret;
-	if ((spiSema != NULL) && (xSemaphoreTake(spiSema, ( TickType_t ) DW1000HAL_SPI_TIMEOUT) == pdTRUE)) {
+	portENTER_CRITICAL();
+	if ((spiSema != NULL) && (xSemaphoreTake(spiSema, 10) == pdTRUE)) {
 		dw1000Hal_chipSelect();
 		ret = HAL_SPI_Transmit(hspi, &dummy, 1, DW1000HAL_SPI_TIMEOUT);
 		if (ret == HAL_OK) {
@@ -122,17 +127,41 @@ int dw1000Hal_readRegister(uint8_t regID, uint8_t *dest, uint16_t len)
 		xSemaphoreGive(spiSema);
 	} else {
 		ret = HAL_LOCKED;
+		trace_printf("nb");
 	}
+	portEXIT_CRITICAL();
 	return ret;
 }
 
+int dw1000Hal_readRegisterFromIsr(uint8_t regID, uint8_t *dest, uint16_t len)
+{
+	uint8_t dummy;
+	dummy = regID & 0x3f; //set the first two bit 0 (read access, no subregister)
+	int ret;
+	if ((spiSema != NULL) && (xSemaphoreTakeFromISR(spiSema, pdFALSE) == pdTRUE)) {
+		dw1000Hal_chipSelect();
+		ret = HAL_SPI_Transmit(hspi, &dummy, 1, DW1000HAL_SPI_TIMEOUT);
+		if (ret == HAL_OK) {
+			ret = HAL_SPI_Receive(hspi, dest, len, DW1000HAL_SPI_TIMEOUT);
+		}
+		dw1000Hal_chipDeselect();
+		while (hspi->State != HAL_SPI_STATE_READY) {
+		}
+		xSemaphoreGiveFromISR(spiSema,pdFALSE);
+	} else {
+		ret = HAL_LOCKED;
+		trace_printf("ib");
+	}
+	return ret;
+}
 int dw1000Hal_writeRegister(uint8_t regID, uint8_t *src, uint16_t len)
 {
 	uint8_t dummy;
 	dummy = regID & 0x3f; //set the first two bit 0 (read access, no subregister)
 	dummy |= 0x80; 		 //set first byte 1 (write access)
 	int ret;
-	if ((spiSema != NULL) && (xSemaphoreTake(spiSema, ( TickType_t ) DW1000HAL_SPI_TIMEOUT) == pdTRUE)) {
+	portENTER_CRITICAL();
+	if ((spiSema != NULL) && (xSemaphoreTake(spiSema, 10) == pdTRUE)) {
 		dw1000Hal_chipSelect();
 		ret = HAL_SPI_Transmit(hspi, &dummy, 1, DW1000HAL_SPI_TIMEOUT);
 		if (ret == HAL_OK) {
@@ -144,6 +173,30 @@ int dw1000Hal_writeRegister(uint8_t regID, uint8_t *src, uint16_t len)
 		xSemaphoreGive(spiSema);
 	} else {
 		ret = HAL_LOCKED;
+		trace_printf("na");
+	}
+	portEXIT_CRITICAL();
+	return ret;
+}
+int dw1000Hal_writeRegisterFromIsr(uint8_t regID, uint8_t *src, uint16_t len)
+{
+	uint8_t dummy;
+	dummy = regID & 0x3f; //set the first two bit 0 (read access, no subregister)
+	dummy |= 0x80; 		 //set first byte 1 (write access)
+	int ret;
+	if ((spiSema != NULL) && (xSemaphoreTakeFromISR(spiSema, pdFALSE) == pdTRUE)) {
+		dw1000Hal_chipSelect();
+		ret = HAL_SPI_Transmit(hspi, &dummy, 1, DW1000HAL_SPI_TIMEOUT);
+		if (ret == HAL_OK) {
+			ret = HAL_SPI_Transmit(hspi, src, len, DW1000HAL_SPI_TIMEOUT);
+		}
+		dw1000Hal_chipDeselect();
+		while (hspi->State != HAL_SPI_STATE_READY) {
+		}
+		xSemaphoreGiveFromISR(spiSema,pdFALSE);
+	} else {
+		ret = HAL_LOCKED;
+		trace_printf("ia");
 	}
 	return ret;
 }
@@ -201,29 +254,29 @@ void vTaskDW1000HAL(void *pvParameters)
 	TickType_t xNextWakeTime;
 	xNextWakeTime = xTaskGetTickCount();
 
-	// all LED GPIOs as output
-	uint8_t gpio_dir = 0xF0;
-	dw1000Hal_writeSubRegister(GPIO_CTRL_ID, GPIO_DIR_OFFSET, &gpio_dir, 1);
+	//Configure the dw1000
+	dw1000Hal_reset();
+	uint32_t sys_mask = 0;
+	dw1000Hal_readRegister(SYS_MASK_ID,&sys_mask,SYS_MASK_LEN);
+	sys_mask |= ( SYS_MASK_MTXFRS | SYS_MASK_MRXDFR | SYS_MASK_MCPLLLL); /* Mask transmit frame sent event	*//* Mask receiver data frame ready event	*/
+	//trace_printf("sys_mask %x\n",sys_mask);
+	dw1000Hal_writeRegister(SYS_MASK_ID,&sys_mask,SYS_MASK_LEN);
+	//set TX LED
+	uint32_t gpio = 0x00001000UL;
+	dw1000Hal_writeSubRegister(GPIO_CTRL_ID,GPIO_MODE_OFFSET,(uint8_t*)&gpio,GPIO_MODE_LEN);
+	uint32_t led = 0;
+	dw1000Hal_readSubRegister(PMSC_ID,PMSC_LEDC_OFFSET,(uint8_t*)&led,PMSC_LEDC_LEN);
+	led |= PMSC_LEDC_BLNKEN;
+	dw1000Hal_writeSubRegister(PMSC_ID,PMSC_LEDC_OFFSET,(uint8_t*)&led,PMSC_LEDC_LEN);
+	//uint8_t event_clear[SYS_STATUS_LEN];
+	//memset(event_clear, 0xff, SYS_STATUS_LEN);
+	//dw1000Hal_writeRegister(SYS_STATUS_ID, &event_clear, SYS_STATUS_LEN);
 
-	// turn on all 4 LEDs
-	uint8_t gpio_dout = 0xFF;
-	dw1000Hal_writeSubRegister(GPIO_CTRL_ID, GPIO_DOUT_OFFSET, &gpio_dout, 1);
 
 	uint8_t led_values = 0;
 
 	while(1){
 		vTaskDelayUntil(&xNextWakeTime, 1000/portTICK_PERIOD_MS);
-		HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_15);
-
-		// count in binary on LEDs
-		gpio_dout = led_values | 0xF0;
-		dw1000Hal_writeSubRegister(GPIO_CTRL_ID, GPIO_DOUT_OFFSET, &gpio_dout, 1);
-
-		led_values += 1;
-
-		if (led_values > 15) {
-			led_values = 0;
-		}
 	}
 	vTaskDelete( NULL );
 }
@@ -270,6 +323,28 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
 
 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
 {
+	if (GPIO_PIN_8 == GPIO_Pin){
+		uint64_t event = 0;
+		uint64_t event_clear = 0;
+		dw1000Hal_readRegisterFromIsr(SYS_STATUS_ID, (uint8_t*)&event, SYS_STATUS_LEN);
+		if (event & SYS_STATUS_TXFRS){ // Frame sent
+			event_clear |= SYS_STATUS_TXFRS ; //clear interrupt
+
+		}
+
+		if (event & SYS_STATUS_RXDFR){ // Frame sent
+			event_clear |= SYS_STATUS_RXDFR; //clear interrupt
+
+		}
+		if (event & SYS_STATUS_CLKPLL_LL){ // Frame sent
+			event_clear |= SYS_STATUS_CLKPLL_LL;
+			if (event & SYS_STATUS_CPLOCK){
+				event_clear |= SYS_STATUS_CPLOCK;
+				//trace_printf("fuu\n");
+			}
+		}
+		dw1000Hal_writeRegisterFromIsr(SYS_STATUS_ID, (uint8_t*)&event_clear, SYS_STATUS_LEN);
+	}
 }