AnsweredAssumed Answered

QN9080-DK hangs up when another device is connected indirectly to it via RS232

Question asked by Christos Mourouzis on Nov 11, 2019
Latest reply on Nov 12, 2019 by Estephania Martinez

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):

  1. Connect to the device via BLE (using private_profile_server baremetal example).
  2. Start communicating with a Pure Photonics PPLC200 Tunable laser via RS232 using the evaluation board PPEB-700.On the QN9080-DK the pins PA09 (RX-input) and PA08(TX-output) are configured as FLEXCOMM1. RX(9) and TX(8) are connected to a MAX3232 RS232 board which is powered by the 3.3V of the board and is connected to the RS232 module of the evaluation board of the laser.

 

===========================================================================================

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:

 

  1.  Start Laser (with RS232 commands; works since I get correct responses and the laser actually starts)
  2. Run the following code to get 32 samples from ADC and send them via I2C. Repeat the process every 1ms.

 

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.

  1. If I don't have the laser connected via RS232 then everything works fine. Meaning that the I2C communication is not interrupted at any moment. I have also tried connecting my laptop as the RS232 device and still everything works fine.
  2. If I have the laser powered on and connected via RS232 and commented out the lines of the I2C communication then the program works ok.
  3. I have tried having the laser turned off and also having the I2C communication running. When I turn on the laser the microcontroller immediately freezes and the led becomes white (instead of red that means that BLE connection was established).
  4. In the debug mode the Thread #1 becomes suspended with a SIGINT signal. The debug console states that Program received signal SIGINT, Interrupt and breaks at 0x3000738.
  5. In conclusion, when the laser is powered on and connected (indirectly) via the MAX3232 RS232 board with the QN9080-DK the I2C communication stops working.

 

Since this is very critical I would like to ask:

  1. What might be interfering with the I2C?
  2. Is it possible to debug this using the MCUXPRESSO debug features?
  3. I can send you anything that you want in order to help me. Please let me know.

 

Thank you very much!

Outcomes