This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

cc2540 disconnected device

Other Parts Discussed in Thread: CC2540

Hi,

I have a problem with events in cc2540.

I have a event called SBP_UPDATE_MEM_EV to write in a spi memory. When the event is executed the comunication fall and the device (phone) show me "disconnect of device".

if ( events & SBP_UPDATE_MEM_EVT )
  {
    update_memory();
    return ( events ^ SBP_UPDATE_MEM_EVT );
  }

static void update_memory(void){
  SPIFlashWriteEnable(); 
  SPIFLASH_erase_sector(0, 0);
  //NAME
  SPIFlashPageWrite(0x000000, NAME, sizeof(NAME));
  //PUK
  SPIFlashPageWrite(0x000100, PUK, sizeof(PUK));
  //PIN
  SPIFlashPageWrite(0x000200, PIN, sizeof(PIN));
  //GPS_INT
  SPIFlashPageWrite(0x000300, (unsigned char *)TIME_GPS, sizeof(GPS_INT));

}

It's weird because if I only I execute the first two or the last 4 instructions in update_memory()  it works fine, but if I execute all instruction, the communication fall.

Why that is happen?


Thanks.

  • Hi

    I hit similiar problem. Ive got LCD based on st7565r connected via SPI. Almost every data transfer to SPI my bluetooth connection is interrupted.

    Im using following config:

    PERCFG |= 0x02;
    
    baud_exponent = 16; // 15
    baud_mantissa = 0;
    
    /* Configure SPI */
    U1UCR = 0x80; /* Flush and goto IDLE state. 8-N-1. */
    U1CSR = 0x00; /* SPI mode, master. */
    U1GCR = HAL_SPI_TRANSFER_MSB_FIRST | HAL_SPI_CLOCK_PHA_0 | HAL_SPI_CLOCK_POL_LO | baud_exponent;
    U1BAUD = baud_mantissa;

    Changing baud rate doesnt help. I even rewritten my code not to use SPI but to emulate SPI using standard GPIO - the same thing happens - bluetooth randomly disconnects.

    Any idea guys ?

    Thanks,

    Sebastian

  • Hello again,

    Today I managed to solve connection interruption while SPI transfer takes place.

    Just create new OSAL task. In ProcessEvent loop of this task do your SPI transfer, then call osal_set_event to start SPI transfer.

    Hope that helps,

    Sebastian

  • Hi,

    I did it, I create a new event call SBP_UPDATE_MEM_EVT to update memory information by update_memory function. This function only execute commands to write in memory. If I execute all commands the pheripheral is disconected.

    I think i have a maximun of comands to execute in a event. For example, I add in update_memory function:

    while(num--)
      {
        asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
        asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
        asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
        asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
        asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
        asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop");
        asm("nop"); asm("nop");
      }

    If num is less than 100000, it works fine, but if num is more, the device is disconnected.



  • Hi,

    In my case using events was not sufficient. I have to create a new task, register it with osal, and send SPI data from that task - not the main one.

    Have you tried this way ?

    Thanks,

    S

  • Hi Sebastian,

    No, I didn't try that way. I'll do it and I'll write the result.

    Thanks.

    Ruben

  • Hi,

    You can't have any operation which lasts more than 2x connection interval. If this happens, the connection will die as the radio hardware isn't completely autonomous.

    Preferably, all your operations should take a maximum of 1/2 of a worst case connection interval (7.5ms -> 3-4ms) and if the operation takes more time, split it up by setting an event on your own task.

    This is to guarantee that the LL task has time to run on schedule. But you could potentially do something like process for 1.9xCI and deliberately stall the radio for one connection event, if it's something terribly important.

    Best regards,
    Aslak 

  • thank you very much, the acces to memory take more than 4 ms and probably this is the cause te connection die.

    It's very important to read, erase and write in memory. How can I stall the radio and after continue in the last state?

    thanks,

    Ruben

  • Hi,

    Aslak,I need to configued the GPS but this proccess will last more than 4ms.

    what can I do to configure the GPS without communication fails?

    Thanks.