This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Code for multiple interfaces (I2C, UART, and USB)

I am currently using the ble_app_uart example but I want to add USB and I2C interface to this solution. Would I need to find what files differ/need to be added from USB and 12C examples in the peripheral folder and incorporate those? Or would I also have to change pin mapping, memory, etc.?

Parents
  • Hello,

    Would I need to find what files differ/need to be added from USB and 12C examples in the peripheral folder and incorporate those?

     Yes, for example, to add TWI to the ble_app_uart example, you will need to add the nrfx_twim driver ( or nrfx_twis if the device is acting as slave ) to your project files, and along with the configuration defines to the sdk_config file. You should also check that the peripheral you are adding does not use the same shared resources as already present peripherals.
    I have included an example to demonstrate how this might be done - however, I unfortunately do not have a TWI sensor with me right now to test the functionality of the example, but this is how you may go about adding a peripheral to one of the examples.

    Bear in mind that the included example is created to demonstrate how you may add a peripheral to your example, and I would recommend that you yourself make these changes to your own project rather than to use this example as basis for your development. I would recommend against the latter.

    Or would I also have to change pin mapping, memory, etc.?

    You might have to change pin mapping, depending on which pins are already in use by the different examples you are merging - so as to avoid using the same pin for multiple purposes.

    Please do not hesitate to let me know if anything still should be unclear, or if you have any other questions or issues!

    Best regards,
    Karl
    _ble_app_uart_with_twim.zip

  • Thanks Karl. Would you recommend starting with the USBD__BLE_UART example file because I have two different data signals (one coming from USB, one from UART) that I need to transmit via Bluetooth. The I2C is more for in board stuff and that data does not need to be transmitted via BT.

  • No problem at all, I am happy to help!

    I would recommend that you start with the ble_app_uart example in this case, and then add both the TWIM and USBD peripheral like I showed in the provided example.
    I would recommend this so that you do not have to add the BLE functions to another example yourself, as it is much more things to add to configure and enable BLE compared to adding hardware peripherals to your project.

    Best regards,
    Karl

  • Ok, but I didn't think the peripheral USB example sends USB data via BT? I myself am a bit confused how to set that up and take into account things like UART and USB trying to send information at the same time over BT.

  • It's no different from any other situation where you have multiple sources of data, and a single comms link.

    You will need to have something that collects all the data from all the sources, marshals it, and then sends it over the link in an orderly fashion. 

  • Hello again Dan,

    Sorry for my terribly late reply - I have been out of office for some time.

    Are you still experiencing any issues, or is something still unclear?

    What Awneil said in regards to how you should setup your communication is correct. I assume that you by now have taken a look at the Nordic UART example that I referenced, and seen how it works. By implementing the approach Awneil outlines, you could schedule the data for BLE transfer by modifying the UART event handler of the Nordic UART example - i.e "when there is new data, transfer .. ".

    Best regards,
    Karl

Reply
  • Hello again Dan,

    Sorry for my terribly late reply - I have been out of office for some time.

    Are you still experiencing any issues, or is something still unclear?

    What Awneil said in regards to how you should setup your communication is correct. I assume that you by now have taken a look at the Nordic UART example that I referenced, and seen how it works. By implementing the approach Awneil outlines, you could schedule the data for BLE transfer by modifying the UART event handler of the Nordic UART example - i.e "when there is new data, transfer .. ".

    Best regards,
    Karl

Children
No Data
Related