In out design DA14583 is connected to PIC16LF1824 MCU that do many things including onewire interface etc. the onewire interface itself can be accessed directly by another device or over USB. I will not go into details as they doesn't matter.
What does matter is that i need (for firmware update) secondary bootloader to be loaded in DA SysRAM from PIC16, so it is practically limited to 1kB total.
This excludes using SDK routines and tools, but with open source tools (gcc) and no libraries i am able to do LED blinker in 72 bytes. so 1kB for secondary bootloader is achievable.
BUT my problem is with UART. i tried to add basic uart transmitting only 'x' characters at 57600 bps.
so far i try to use UART without interrupts. no success, UART_THRE bit in UART_LSR_REG is always 0
只有不断地把“x”UART交易nsmit register too - nothing is sent.
seems like UART is blocked some way.
my minimal code (blink led and send 'x' over uart) is below:
define mem2(x) (*((volatile unsigned short *)x))
#define clear_watch mem2(0x50003100)=0x007F;
#define P0_SET_DATA_REG mem2(0x50003002)
#define P0_RESET_DATA_REG mem2(0x50003004)
#define UART_RXTX_REG mem2(0x50001000)
#define UART_IER_DLH_REG mem2(0x50001004)
#define UART_LCR_REG mem2(0x5000100C)
#define UART_LSR_REG mem2(0x50001014) //patrz strona 42 instrukcji
#define UART_MSR_REG mem2(0x50001018) //patrz strona 43 instrukcji
volatile int led_count;
//dokumentacja w da14583_ds_3v0.pdf
//Chcemy 57600 baud, mamy zegar 16000000Hz, 57600=16*10^6/(16*divisor)
//divisor=10000000/57600=17
#define UART_divisor 17
void main() {
//port P0_0 set to UART1 TX
mem2(0x50003006)=0x0302;
//port P0_1 set to UART1 RX
mem2(0x50003008)=0x0001;
//port P0_2 set as output, LED is connected here
mem2(0x5000300A)=0x0300;
//ENABLE FIFO, REGISTER FCR IF UART_LCR_REG.DLAB=0
// XMIT FIFO RESET, RCVR FIFO RESET, FIFO ENABLED
// SetBits16(UART_LCR_REG, UART_DLAB, 0);
UART_LCR_REG&=~0x80;
//SetWord16(UART_IIR_FCR_REG,7);
mem2(0x50001008)=7;
//DISABLE INTERRUPTS, REGISTER IER IF UART_LCR_REG.DLAB=0
//SetWord16(UART_IER_DLH_REG, 0);
UART_IER_DLH_REG=0;
// ACCESS DIVISORLATCH REGISTER FOR BAUDRATE 115200, REGISTER UART_DLH/DLL_REG IF UART_LCR_REG.DLAB=1
// SetBits16(UART_LCR_REG, UART_DLAB, 1);
UART_LCR_REG|=0x80;
// SetWord16(UART_IER_DLH_REG,0); // for serial clk 16MHz baudrate 115200
// SetWord16(UART_RBR_THR_DLL_REG,9); // set baudrate ~115200 = serial_clk/(16*9)
UART_IER_DLH_REG=0;
UART_RXTX_REG=17;
// NO PARITY, 1 STOP BIT, 8 DATA LENGTH AND
//SetWord16(UART_LCR_REG,3);
UART_LCR_REG=3;
//SetBits16(UART_LCR_REG, UART_DLAB, 0);
UART_LCR_REG&=~0x80;
//no interrupts
UART_IER_DLH_REG=0;
while(1) {
// while(!(UART_LSR_REG&0x20));
UART_RXTX_REG='x';
if((led_count++)&0x40000)
P0_SET_DATA_REG=4;
else
P0_RESET_DATA_REG=4;
clear_watch; }
}
typedef void (*irqhandler)();
irqhandler const vectors[] __attribute__ ((section (".vectors")))={
(irqhandler)0x20009800,main};
Problem just solved. UART works much better if UART clock is enabled in CLK_PER_REG register ;)
Hi w.puchar,
Glad you figured it out, thanks for indicating
Thanks, PM_Dialog