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

Using pin 6 as GPIO in SPI functionality

How do I find where else in the program pin 6 is being used and disable its other functionalities in the BLE_UART example? 

I am trying to read data from a sensor via SPI communication and then transfer the data the SPI reads via bluetooth to the Nordic mobile app. I am starting with the ble_uart example and add SPI instance and functions. IDE is Embedded Studio, SDK 15.2, and the chip I am programming is a custom made PCB device (nrf52832). Program builds and flashes alright and the chip advertises and sends random data too. 

But I cannot seem to use pin # 6 on my device as a GPIO. It's HIGH (3.3V) even though I am clearing it in the program. This is important because pin 6 is a chip select for my ADC (ADS1220) so I need to fix it to LOW and make sure my pins are being defined correctly as SPI pins and not being used in other things.

I previously had the same problem when I was working with the SPI master example on my chip. I fixed it by redefining the UART_TX pin from 6 to pin # 5 in the sdk_config.h file so that I could use pin 6 as a GPIO only and its uart functionality was disabled. This solved the issue. Now that I start with the ble_uart example and add the SPI code and try to work with it I see that my pin 6 does not go low when I clear it. (Same problem I was having before in the spi master example but now  I cannot find any other use of pin 6 in the sdk_config.h file of the ble_uart example. 

Parents
  • The reason you won't find the use of pin 6 in the sdk_config.h file is because it is declared somewhere else. The ble_app_uart example doesn't use the UART backend for logging, and as a consequence does not have any of the defines in the sdk_config.h file, and this solution doesn't help you.

    However, the example uses the function app_uart_put(..), which is called directly from main, and through printf()-->app_uart_put() as well. The pins TX and RX pins are decided through the function APP_UART_FIFO_INIT(), which is called from main in the function uart_init(..).

    Enough talk. Pin 6 is assigned as TX pin in the function uart_init(..) in main.c of the ble_app_uart example.

    Best regards,

    Simon

  • That makes sense. I commented out the uart_init() function in main and ran the program on my device. Pin 6 works fine (i.e. goes high and low according to program). 
    However, when I  remove the uart_init() function, the device stops advertising. I didn't know the uart was important for the ble functionality? How do I remove the uart functions without disrupting the ble or nus functionality? 

    Thanks Simon!

  • The reason advertising stops when you remove uart_init() is because printf() is called before advertising_start(). The function printf() uses the UART parameters to print the data, but since the parameters are never set, the programs hangs at printf() and never calls advertising_init(). If you want to use pin 6, then you won't be able to receive logging through the interface MCU and USB, since pin 6 is connected to the TX line. The solution is to comment out the printf() and the app_uart_put() functions as well.

    Best regards,

    Simon

  • Thank you Simon. Deleting all calls to the uart functions and the NRF_LOG functions solves this problem. 

    I was wondering, if I need the uart functionality, could I re-assign uart TX  and RX pins somewhere in the project? Which file/settings should I look into to reassign these pins to sth else so I can both use pin 6 as gpio and use uart functions? 


    Also, I am not sure if I am supposed to start a new thread/post for this but even though my pin 6 works fine and the SPI communication is working on my custom PCB device, the nus_data_send () function does not send the SPI data to the NRF_TOOLBOX app on my phone.... I've tried calling the nus_data_send() function in the NUS_DATA_HANDLER as well as in main () program and in the spi_event_handler but it doesn't send the data from the SPI instead it sends some random garbage values to the app.

    This is how I call the nus_data_send(). I initialize data_array with values from the RX buf of SPI. 

     

    err_code1 = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
                            if ((err_code1 != NRF_ERROR_INVALID_STATE) &&
                                (err_code1 != NRF_ERROR_RESOURCES) &&
                                (err_code1 != NRF_ERROR_NOT_FOUND))
                            {
                                APP_ERROR_CHECK(err_code1);
                            }
    
    
    

  • noob_with_ucontrollers said:
    I was wondering, if I need the uart functionality, could I re-assign uart TX  and RX pins somewhere in the project? Which file/settings should I look into to reassign these pins to sth else so I can both use pin 6 as gpio and use uart functions?

     The UART RX and TX pins are configured in the function uart_init() in main.c.

    Regarding the second question, you should make a new thread and present your problem there. In that way, the threads will only include content related to the initial question, and it is easier and quicker for people to find answers to their questions.

    Best regards,

    Simon

Reply
  • noob_with_ucontrollers said:
    I was wondering, if I need the uart functionality, could I re-assign uart TX  and RX pins somewhere in the project? Which file/settings should I look into to reassign these pins to sth else so I can both use pin 6 as gpio and use uart functions?

     The UART RX and TX pins are configured in the function uart_init() in main.c.

    Regarding the second question, you should make a new thread and present your problem there. In that way, the threads will only include content related to the initial question, and it is easier and quicker for people to find answers to their questions.

    Best regards,

    Simon

Children
No Data
Related