Hello Dialog,
I am learning UART through your DA14580 Basic kit and and am currently trying to periodically send out a byte via uart to measure with an oscilloscope to see how it works. I have written the following code:
SetWord16(CLK_AMBA_REG, 0x01);
SetWord16(SET_FREEZE_REG,FRZ_WDOG);
SetWord16(CLK_PER_REG, UART1_ENABLE);
SetWord16(UART_LCR_REG, 0x80); // set bit to access DLH and DLL register
SetWord16(UART_IER_DLH_REG,(UART_BAUDRATE_115K2&0xFF>>8));//set high byte
SetWord16(UART_RBR_THR_DLL_REG,UART_BAUDRATE_115K2&0xFF);//set low byte
SetBits16(UART_MCR_REG, UART_SIRE, 0); // mode 0 for normal , 1 for IRDA
SetWord16(UART_IIR_FCR_REG,1); // enable fifo
SetBits16(UART_IER_DLH_REG,ERBFI_dlh0,0); // IER access, disable interrupt for available data
SetBits16 (UART_LCR_REG UART_DLS 0 x03);
SetBits16(P10_MODE_REG, PUPD, 0x03);
SetBits16(P20_MODE_REG, PID, 0x02);
long n, j;
n=0;
j=0;
while(1)
{
while(n<200000){
n++;
}
n=0;
j++;
if(j%2==0){
SetWord16(UART_RBR_THR_DLL_REG, 0x92);
SetBits16(UART_MCR_REG, UART_RTS, 0x01);
}
else{
SetBits16(P1_RESET_DATA_REG, P2_RESET, 0x01);
SetWord16(UART_RBR_THR_DLL_REG,0x0);
}
}
Probing port 2_0 shows high which makes sense because functional but idle UART is held high - however, I cannot find any explicit command to transmit the contents of UART_RBR_THR_DLL_REG once I've filled it with data to be sent. Could you point me in the correct direction with this?
Thanks,
svl0822

Hello svl0822,
You could use uart driver to achieve higher level of abstraction and easier control of UART. This will save you a lot of time since you don't need to think in what order you should control the registers. To do this include uart driver (uart2.c) to your project. You also need to define
CFG_PRINTF_UART2in yourda14580_config.hfile. Definition will include uart initialization in fileperiph_setup.c:#ifdef CFG_PRINTF_UART2
SetBits16(CLK_PER_REG, UART2_ENABLE, 1);
uart2_init(UART_BAUDRATE_115K2, 3);
#endif
Includeuart.hheader file where you want to use UART. Check theuart.hfile to see what functions you have in use.
Remember also pin confiugration inperiph_setup.c配置正确的UART别针。你需要做的functions
GPIO_reservationsandset_pad_functions. You should already find initial definitions.PS: is there some special need to manipulate registers directly? Most likely nothing good follows it. It has been already thought well what is the correct way of handling it so I recommend using the UART driver, or at least you can take example from it.
VesaN,
The higher level code that is included is very confusing for a beginner like me. I cannot follow what is happening across the different files and I'd like to learn the low level register manipulation in order to really understand the process of UART initialization and usage.
In another microcontroller that I've used (MSP430), writing to the register that plays the role of THR immediately sends out the byte in series over the pin configured for UART. Does the DA14580 have similar functionality?
Thanks,
svl0822
VesaN,
I've looked at the files included and have added #include "uart2.c" into my arch_main.c file.
This generated a bunch of errors:
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol UART2_Handler multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_init_func multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_init multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_flow_on_func multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_flow_on multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_flow_off_func multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_flow_off multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_finish_transfers_func multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_finish_transfers multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_read_func multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_read multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_write_func multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol uart2_write multiply defined (by uart2.o and arch_main.o).
, \ \富尔语l_emb_sysram.axf: Error: L6200E: Symbol UART2_Handler_func multiply defined (by uart2.o and arch_main.o).
Should i un-include something from this file now to prevent double definitions?
Hello svl0822,
Generally it is not a good idea to include .c files to your code. This will indeed most likely cause multiple definitions. Try replacing
#include "uart2.c"with#include "uart.h"What do you want to do with UART specifically?
Hello VesaN,
I need the UART to communicate with another uC which will then transmit data to the DA14580 for further wireless transmission.
I have written some code to try to use P2_0 for transmission via UART 2.
periph_init();
uart2_init(UART_BAUDRATE_115K2, 3);
uart2_flow_off();
SetBits16(P20_MODE_REG, PID, 0x4);
uint8_t sample[] = {0x92};
while(1){
uart2_write(sample, 1, NULL);
uart2_finish_transfers();
}
I have also changed the pin configurations in GPIO_ConfigurePin to reserve P2_0 and P2_1 for uart2.
However, I am not seeing anything on P2_0 other than a constant high signal, which means it's been properly initialized for UART and is idling in UART mode. I believe that I should be seeing 10010010 from the 0x92. What do I need to do to be able to see these levels on pin 2_0 of the DA14580?
Thanks,
svl0822
Could someone from Dialog provide some insight? When I load the blinky code and probe the appropriate ports I am able to see the signal for the function printf_string, which is a wrapper for setting the register UART_RBR_THR_DLL_REG to the hex value of the sent character. When I do the same on P2_0 in a project made from the template, I see nothing but constant high signal.
Hello svl0822,
Maybe you can just use functionality of
app_console.c. I think you should configure your pins inperiph_setup.crather than do it manually withSetBits16.Maybe this is useful too?
Sorry, I haven't looked into so low level of manipulating UART