From: malli on 26 Jul 2007 07:10 Actually, i want to tell clearly my problem so ,that iam elaborating...please read till the end......... Actually i am configuring my system baud rate(RS232) t0 19200,8 data bits,1 stop bits,no parity..... and based on the reset values...... MSEL[5:0]=0x0A; and for BF533 EZkit lite kit CLKIN=27Mhz.. so, VCO CLK is:0x0A*27=270MHz... and on the reset the SCEl=0x05 and DF=0; so,SCLK=VCO/5=54MHz......... Based on the formula Baud rate=SCLK/(16*divisor); 19200=54*10^6/(16*divisor); i found divisor =176(APProximately); and the program is like this: i want to first configure serial port 19200,8,1,no so,UART_LCR=0x0083;//enabling DLAB to access DLL and DLH registers *pUART_DLL=0x00b0;// 176=b0; *pUART_DLH=0x0000; then making DLAB clear so,that i can access THR and RBR registers.. and i want to use polling here not the interrupts so, uam dissabling the interrupts... just i want to send @ to the BF533 then it will send 'B'.. After wards whatever i will send from system it has to return it.... #include<cdefBF533.h> //#include<ccblkfn.h> void serialin() { *pUART_LCR=0x0083; *pUART_DLL=0x00b0; *pUART_DLH=0x0000; *pUART_LCR=0x0003; } void main() { int a; serialin(); *pUART_GCTL=0x0001; *pUART_IER=0x0000; //polling for whether dat ready signal //is set or not while(((*pUART_LSR) ^ 0x0060) == 0x0060 ); if ((*pUART_RBR)==0x0040) { *pUART_THR='B'; while(((*pUART_LSR) ^ 0x0040) == 0x0000 ); while(1) { while(((*pUART_LSR) ^ 0x0060) == 0x0000 ); a=*pUART_RBR; *pUART_THR=a; while(((*pUART_LSR) ^ 0x0040) == 0x0000 ); } } } Actually i checked this code in BF533 EZkit-lite...the problem iam facing is it is halting at the statement while(((*pUART_LSR) ^ 0x0060) == 0x0060 ); and unable to move.. may be iam thinking '@' i have entered in the hyperterminal is not reaching the UART_RBR register becausse of baud rate mismatches..(or) it is not coming to receive shift register......... i have given the baud rate and other settings correctly in the system serial port.... i don't know any may be the case... so, if any body know please help... one more i want to see transmit buffer and receive buffer is it possible or not..???????????????????????
From: Jim Thomas on 26 Jul 2007 09:34 malli wrote: > while(((*pUART_LSR) ^ 0x0060) == 0x0060 ); and unable to move.. You do realize that the only thing you can xor with 0x0060 and get a result of 0x0060, is 0x0000, right? I don't understand what you're trying to do here. Why not just do this: while (!*pUART); // wait until *pUART == 0 -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas(a)bittware.com http://www.bittware.com (603) 226-0404 x536 Having a smoking section in a restaurant is like having a peeing section in a swimming pool.
From: Vladimir Vassilevsky on 26 Jul 2007 10:17 malli wrote: > Actually, i want to tell clearly my problem so ,that iam > elaborating...please read till the end......... >> so,UART_LCR=0x0083;//enabling DLAB to access DLL and DLH registers No, I won't read this to the end, because your code is rubbish. Are you seriously expecting anyone to check your unnamed bits and constants against the datasheets? Here is the RS232 driver of HALOS RTOS developed by professionals for professionals. You can find all initializations in there. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com /*********************************************/ #ifndef __UART_H_INCLUDED #define __UART_H_INCLUDED #include "HALOS/Config/main_defs.h" #include "HALOS/Config/interrupt_assignment.h" #include "HALOS/Multitask/interrupts.h" #include "HALOS/Multitask/messages.h" #include "HALOS/Common/fifo.h" const u32 DEFAULT_UART_TX_FIFO_SIZE = 16; const u32 DEFAULT_UART_RX_FIFO_SIZE = 16; const u32 DEFAULT_UART_BAUD_RATE = 9600; const u8 DEFAULT_UART_ID = 0; class UART { FIFO <u8> *rx_fifo; FIFO <u8> *tx_fifo; HALOS_MESSAGE hm_rx; HALOS_MESSAGE hm_tx; u8 id; u8 ValidBaudRate(u32 baud_rate); void TxIntHandler(); // Called from the interrupt void RxIntHandler(); // Called from the interrupt friend void UART_RX_Int_Handler(void *); friend void UART_TX_Int_Handler(void *); public: UART(u16 rx_fifo_size = DEFAULT_UART_TX_FIFO_SIZE, u16 tx_fifo_size = DEFAULT_UART_TX_FIFO_SIZE, u32 baud_rate = DEFAULT_UART_BAUD_RATE, u8 uart_id = DEFAULT_UART_ID); ~UART(); u8 GetChar(u8 &x); // returns nonzero on success u8 PutChar(u8 x); // returns nonzero on success u32 CheckTx(); // Returns number of bytes in Rx FIFO u32 CheckRx(); // Returns free space in Tx FIFO u8 SetBaudRate(u32 baud_rate = DEFAULT_UART_BAUD_RATE); u16 Rx_Msg_Id(); // Sent on every received byte u16 Tx_Msg_Id(); // Sent on every transmitted byte }; // Aux. functions static void UART_RX_Int_Handler(void *uart); static void UART_TX_Int_Handler(void *uart); #endif // BlackFin BF537 UART #include "uart.h" static const u16 UART_MSG_QUEUE_LENGTH = 4; #define UDRE_INT_ENABLE *IER |= 0x0002 #define UDRE_INT_DISABLE *IER &= ~0x0002 #define RXC_INT_ENABLE *IER |= 0x0001 #define RXC_INT_DISABLE *IER &= ~0x0001 #define UART_TX_COMPLETE ((*LSR)&0x0040) #define UART_UDRE ((*LSR)&0x0020) #define UART_RXC ((*LSR)&0x0001) static u16 volatile * const uart_register[NUMBER_OF_UARTS][9] = { { pUART0_DLL, pUART0_DLH, pUART0_LCR, pUART0_MCR, pUART0_RBR, pUART0_IER, pUART0_THR, pUART0_GCTL, pUART0_LSR }, { pUART1_DLL, pUART1_DLH, pUART1_LCR, pUART1_MCR, pUART1_RBR, pUART1_IER, pUART1_THR, pUART1_GCTL, pUART1_LSR } }; #define DLL uart_register[id][0] #define DLH uart_register[id][1] #define LCR uart_register[id][2] #define MCR uart_register[id][3] #define RBR uart_register[id][4] #define IER uart_register[id][5] #define THR uart_register[id][6] #define GCTL uart_register[id][7] #define LSR uart_register[id][8] //----------- Interrupt id ------------- static const u16 uart_rx_int_id[NUMBER_OF_UARTS] = { dma8_uart0_rx_int_id, dma10_uart1_rx_int_id }; static const u16 uart_tx_int_id[NUMBER_OF_UARTS] = { dma9_uart0_tx_int_id, dma11_uart1_tx_int_id }; //----------------------------------------------------------------------- UART::UART(u16 rx_fifo_size, u16 tx_fifo_size, u32 baud_rate, u8 uart_id) { rx_fifo = new FIFO <u8> (rx_fifo_size); tx_fifo = new FIFO <u8> (tx_fifo_size); id = uart_id; if(id > NUMBER_OF_UARTS) id = 0; Install_Interrupt_Handler(UART_RX_Int_Handler, (void *)this, UART_RX_interrupt_priority, uart_rx_int_id[uart_id]); Install_Interrupt_Handler(UART_TX_Int_Handler, (void *)this, UART_TX_interrupt_priority, uart_tx_int_id[uart_id]); if(!SetBaudRate(baud_rate)) { SetBaudRate(DEFAULT_UART_BAUD_RATE); } *GCTL = 0x0001; // UART clock enable hm_rx.msg_id = halos_Register_Message(UART_MSG_QUEUE_LENGTH); hm_rx.msg = this; hm_tx.msg_id = halos_Register_Message(UART_MSG_QUEUE_LENGTH); hm_tx.msg = this; } //---------------------------------- UART::~UART() { UDRE_INT_DISABLE; RXC_INT_DISABLE; Remove_Interrupt_Handler(uart_rx_int_id[id]); Remove_Interrupt_Handler(uart_tx_int_id[id]); delete(rx_fifo); delete(tx_fifo); *GCTL = 0x0000; // Disable UART clock } u16 UART::Rx_Msg_Id() { return hm_rx.msg_id; } u16 UART::Tx_Msg_Id() { return hm_tx.msg_id; } u8 UART::GetChar(u8 &x) { RXC_INT_DISABLE; ssync(); u8 ret_value = rx_fifo->Get(x); RXC_INT_ENABLE; return ret_value; } u8 UART::PutChar(u8 x) { UDRE_INT_DISABLE; ssync(); u8 ret_value = tx_fifo->Put(x); UDRE_INT_ENABLE; return ret_value; } u32 UART::CheckRx() { RXC_INT_DISABLE; ssync(); u32 items = rx_fifo->Items(); RXC_INT_ENABLE; return items; } u32 UART::CheckTx() { UDRE_INT_DISABLE; ssync(); u32 items = tx_fifo->FreeItems(); UDRE_INT_ENABLE; return items; } //------------------------------------------- u8 UART::ValidBaudRate(u32 baud_rate) { u32 divider, speed, diff; if(!baud_rate) return 0; divider = BUS_CLOCK/baud_rate; divider = (divider + 0x0008)>>4; // Round to the nearest and divide by 16 if(!divider) return 0; if(divider > 65536) return 0; speed = BUS_CLOCK/divider; // actual speed x 16 diff = abs((s32)(speed - (baud_rate<<4))); // absolute difference x 16 if((diff<<3) > baud_rate) return 0; // (abs. difference * 128) > baud_rate -> low tolerance return 1; } //-------------------------------- u8 UART::SetBaudRate(u32 baud_rate) { u32 divider; u8 dummy; if(!UART::ValidBaudRate(baud_rate)) return 0; divider = BUS_CLOCK/baud_rate; divider = (divider + 0x0008)>>4; // Round to the nearest and divide by 16 UDRE_INT_DISABLE; RXC_INT_DISABLE; ssync(); dummy = *RBR; // Clear the interrupt just in case *LCR = 0x0083; // 0000 0000 1000 0011 8-bit, no parity, DLL/DHL access *DLH = (divider>>8)&0xFF; *DLL = divider&0xFF; // Baud = SCLK/(16*(DLH:DLL)) *LCR = 0x0003; // 0000 0000 0000 0011 8-bit, no parity, THR/RBR/IER access *MCR = 0x0000; // no loopback ssync(); RXC_INT_ENABLE; return 1; } void UART::RxIntHandler() { u8 x; if(UART_RXC) { x = (u8)(*RBR); rx_fifo->Put(x); halos_Send_Message(hm_rx); } } void UART::TxIntHandler() { u8 x; if(UART_UDRE) { if(tx_fifo->Items()) { tx_fifo->Get(x); *THR = x; halos_Send_Message(hm_tx); } else { UDRE_INT_DISABLE; } } } //-------------------------------------------------------- static void UART_RX_Int_Handler(void *uart) { ((UART *)uart)->RxIntHandler(); } static void UART_TX_Int_Handler(void *uart) { ((UART *)uart)->TxIntHandler(); } //======================= <END> ===================
From: Jerry Avins on 26 Jul 2007 15:21 Jim Thomas wrote: > ... Why not just do this: > > while (!*pUART); // wait until *pUART == 0 Jim, I don't understand that syntax. I would have expected while (!*pUART); // wait until *pUART !== 0 or while (!*pUART); // wait until *pUART Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
From: Jim Thomas on 30 Jul 2007 09:51 Jerry Avins wrote: > Jim Thomas wrote: > >> ... Why not just do this: >> >> while (!*pUART); // wait until *pUART == 0 > > Jim, > > I don't understand that syntax. I would have expected > > while (!*pUART); // wait until *pUART !== 0 > or while (!*pUART); // wait until *pUART > > Jerry My mistake. The comment was wrong. -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas(a)bittware.com http://www.bittware.com (603) 226-0404 x536 The secret to enjoying your job is to have a hobby that's even worse - Calvin's Dad
|
Pages: 1 Prev: Best DSP for guitar effects Next: CCDF Plot of OFDM PAPR |