Hello,
I am facing a very strange behaviour from the QN9080-DK v1.3 which I cannot debug and explain. What I am trying to achieve is (including the description of my setup):
===========================================================================================
RS232 Configuration
===========================================================================================
/* RS232 - Laser Controller */
usart_config_t config2;
USART_GetDefaultConfig(&config2);
config2.baudRate_Bps = 9600;
config2.enableTx = true;
config2.enableRx = true;
USART_Init(DEMO_USART1, &config2, DEMO_USART_CLK_FREQ); //FLECOMM1 RS232 baudrate = 9600
/* Enable RX interrupt FLEXCOMM1 for RS232 */
USART_EnableInterrupts(DEMO_USART1, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);
EnableIRQ(DEMO_USART_IRQn1);
3. After starting the laser (via RS232), start collecting from the ADC the samples of a photodiode's output (ADC is configured to the PA11 (ADC7) pin of the board and its values are read with DMA on ADC_DMA_CHANNEL 14. While collecting the samples send a byte array of 32 floats to an Arduino via I2C. I2C is configured as FLEXCOMM2 - PA05 as SCL and PA04 as SDA.
===========================================================================================
ADC CONFIGURATION
===========================================================================================
/* ADC */
#define DEMO_ADC_BASE ADC /* Demo base address */
#define DEMO_ADC_CHANNEL 11 /* Select channel */
#define DEMO_ADC_CFG_IDX 0 /* Select configuration */
#define DEMO_ADC_TRIGGER kADC_TriggerSelectSoftware /* Software trigger */
#define DEMO_ADC_DMA_CHANNEL 14
/***********ADC configuration**************/
DMA_Init(DMA0);
DMA_EnableChannel(DMA0, DEMO_ADC_DMA_CHANNEL);
DMA_CreateHandle(&g_adcDmaHandle, DMA0, DEMO_ADC_DMA_CHANNEL);
DMA_SetCallback(&g_adcDmaHandle, ADC_ConvertDMACallback, NULL);
DMA_PrepareTransfer(&transferConfig, (void *)&DEMO_ADC_BASE->DATA, &g_AdcConvResult, sizeof(uint32_t), 4,
kDMA_PeripheralToMemory, NULL);
DMA_SubmitTransfer(&g_adcDmaHandle, &transferConfig);
/* Power on ADC */
POWER_EnableADC(true);
/* Configure the converter and work mode. */
ADC_Configuration();
static void ADC_Configuration(void)
{
adc_config_t adcConfigStruct;
adc_sd_config_t adcSdConfigStruct;
/**
* Initial ADC to default configuration.
*/
ADC_GetDefaultConfig(&adcConfigStruct);
adcConfigStruct.channelEnable = (1U << DEMO_ADC_CHANNEL);
adcConfigStruct.channelConfig = (DEMO_ADC_CFG_IDX << DEMO_ADC_CHANNEL);
adcConfigStruct.triggerSource = DEMO_ADC_TRIGGER;
adcConfigStruct.convMode = kADC_ConvModeSingle;
adcConfigStruct.clock = kADC_Clock2M;
adcConfigStruct.dataFormat = kADC_DataFormat0WithoutIdx;
ADC_Init(DEMO_ADC_BASE, &adcConfigStruct);
/* Initial ADC Sigma Delta(SD) configuration */
ADC_GetSdDefaultConfig(&adcSdConfigStruct);
ADC_SetSdConfig(DEMO_ADC_BASE, DEMO_ADC_CFG_IDX, &adcSdConfigStruct);
/* Bandgap voltage */
g_AdcBandgap = ADC_GetBandgapCalibrationResult(DEMO_ADC_BASE, DEMO_ADC_CFG_IDX);
/* Calibration VINN value */
g_AdcVinn = ADC_GetVinnCalibrationResult(DEMO_ADC_BASE, &adcConfigStruct);
/* Enable ADC */
ADC_Enable(DEMO_ADC_BASE, true);
}
===========================================================================================
I2C CONFIGURATION
===========================================================================================
#define EXAMPLE_I2C_MASTER_BASE (I2C1_BASE)
#define I2C_MASTER_CLOCK_FREQUENCY (8000000)
#define I2C1_IRQn FLEXCOMM2_IRQn
#define EXAMPLE_I2C_MASTER ((I2C_Type *)EXAMPLE_I2C_MASTER_BASE)
#define I2C_MASTER_SLAVE_ADDR_7BIT (0x08U)
#define I2C_BAUDRATE (100000) /* 100K */
#define I2C_DATA_LENGTH (32) /* MAX is 256 */
I2C_MasterGetDefaultConfig(&masterConfig);
//Change the default baudrate configuration
masterConfig.baudRate_Bps = I2C_BAUDRATE;
//Initialize the I2C master peripheral
I2C_MasterInit(EXAMPLE_I2C_MASTER, &masterConfig, I2C_MASTER_CLOCK_FREQUENCY);
A simple test is:
startReadings = true;
delayMux();
where:
static void delayMux(void)
{
if(!TMR_IsTimerActive(mStartTimerId)){
TMR_StartSingleShotTimer(mStartTimerId, TmrMilliseconds(1), PhotodiodeReadingsCallback, NULL); }
}
static void PhotodiodeReadingsCallback(void * pParam)
{
float g_master_buffFloat[I2C_DATA_LENGTH];
if (startReadings){
for (uint8_t i=0; i<I2C_DATA_LENGTH; i++) {
g_AdcConvSeqCpltFlag = false;
DMA_StartTransfer(&g_adcDmaHandle);
/* Do software trigger */
ADC_DoSoftwareTrigger(DEMO_ADC_BASE);
/* Wait for complete */
while (!g_AdcConvSeqCpltFlag)
{
}
g_master_buffFloat[i] = ADC_ConversionResult2Mv(DEMO_ADC_BASE, DEMO_ADC_CHANNEL, DEMO_ADC_CFG_IDX,
g_AdcBandgap, g_AdcVinn, g_AdcConvResult);
}
if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))
{
reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, g_master_buffFloat, sizeof(g_master_buffFloat), 0);
reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);
}
delayMux();
}
else{
g_master_buffFloat[0] = -1;
if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))
{
reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, g_master_buffFloat, sizeof(g_master_buffFloat), 0);
reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);
}
}
}
===========================================================================================
THE PROBLEM
===========================================================================================
The problem is that when the laser is connected and powered (plugged in a wall socket) the board hangs up after sending 3-4 packets via I2C.
Since this is very critical I would like to ask:
Thank you very much!
Hello ,
I can think of several things that might be affecting your system. Something that I saw in the code you added to the thread is a delay, if you add this type of delays, you might be creating a blocking element which definitely is affecting the Bluetooth LE stack.
The Bluetooth LE stack, includes an operative system in order to manage the task and be compliant with the protocol specification, if you add a blocking element to you code, you might have some issues in the flow of your application.
You can also be out of memory, you can try adding the following definitions in order to help your debug.
#define gUsePanic_c 1
#define MEM_TRACKING
#define MEM_STATISTICS
#define MEM_DEBUG
#define MEM_DEBUG_OUT_OF_MEMORY
If you are using the master I2C interface, you can check this guide on how to add the interface in the connectivity framework. Did you add/enable the low power capabilities in your application ?
Regards,
Estephania