Hi !
I am trying to create a buffer for UART 2 of P24f. The sample application on uart2 works fine..i.e. receive data and transfer data back to TX port.
I use a simple code as under
program Uart2_example
dim X as word[150]
dim y as byte
sub procedure rxb org $0050
dim rx2 as word
dim cnt as byte
cnt=0
if Uart2_Data_Ready = 1 then
rx2=Uart2_Read_Char
uart2_Write_Char(rx2)
X[cnt]=rx2
inc (cnt)
end if
IFS1.14=0
for y=1 to 150
uart2_write_char(x[y])
next y
end sub
main:
IEC1.14=1
Uart2_Init(9600)
while true
delay_ms(1000)
wend
end.
but it doesnt work. I would appreciate if someone could help me out. Thanks in advance.
regards,
NIkhil
Buffer on UART port for 150 characters
From you code it looks like you want an interrupt to happen
if so then you have now where in your code enabled the IEC interrupt control register bits for the UART and the IP registers
if you do not want an interrupt tp happen then you need to call the function in your main code but then you need not to specify the ORG $0050 ,
Also if you want to transmit 150 bytes one after another you should check in your code whether the UART is Busy before you try to load the next byte you Transmit loop does not do this
Regards
if so then you have now where in your code enabled the IEC interrupt control register bits for the UART and the IP registers
if you do not want an interrupt tp happen then you need to call the function in your main code but then you need not to specify the ORG $0050 ,
Also if you want to transmit 150 bytes one after another you should check in your code whether the UART is Busy before you try to load the next byte you Transmit loop does not do this
Regards
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------
Hi P.Erasmus,
Thanks for the reply to my post.
Further to the same, I've put IEC1.14=1 just under the main program to enable interrupt. Also, I really dont want to transmit, I want to capture (create a buffer) for any data which is being received in RX register upto 150 bytes / characters since the MCU only has a word fifo and we want to basically create a buffer for the uart port.
I look forward to your advise. Thanks in advance.
regards,
Nikhil
Thanks for the reply to my post.
Further to the same, I've put IEC1.14=1 just under the main program to enable interrupt. Also, I really dont want to transmit, I want to capture (create a buffer) for any data which is being received in RX register upto 150 bytes / characters since the MCU only has a word fifo and we want to basically create a buffer for the uart port.
I look forward to your advise. Thanks in advance.
regards,
Nikhil
seems this is still not easy to find : http://www.mikroe.com/forum/viewtopic.php?t=20232 , you may need to adapt buffersize and interrupt vector addresses perhaps
Au royaume des aveugles, les borgnes sont rois.
nikhil
To receive a buffer of chars your code should look something like this
To initialize the controller a better way is using a procedure
you program should look something like this
my code is not sending any Char you have to send a Char from the main loop to start the Intterrupt and you have to send 150 chars
if you place a break point inside the interrupt and then send the char your debugger should then stop at the break point in the interrupt indicating the interrupt is fired ,
Hope this helps you
regards
To receive a buffer of chars your code should look something like this
Code: Select all
sub procedure rxb org $0050
if (Uart2_Data_Ready = 1) then 'if data in Uart read
rx2 = Uart2_Read_Char 'read and put in Buffer
X[cnt] = rx2
inc (cnt) 'Increment buffer pointer
end if
IFS1.14=0 'clear INT flag U2
if (cnt = 149)Then 'check if 150 bytes in buffer
cnt = 0
end if
end sub
Code: Select all
sub procedure Init()
INTCON1.15 = 1 'nested interupts disabled
IEC1.14 = 1 'Enable U2RXIE
IFS1.14 = 0 'Clear Interupt Flag U2RX
Uart2_Init(2400)
cnt = 0 ' Clear Rx Buffer pointer
end sub
Code: Select all
'********************************************************
program Uart2_example
'********************************************************
'*******************************************************
'Global variables
'*******************************************************
dim X as word[150]
dim rx2 as word
dim y as byte
dim cnt as byte
'*******************************************************
'*******************************************************
'Interrupt Handler U2Rx
'*******************************************************
sub procedure rxb org $0050
if (Uart2_Data_Ready = 1) then 'if data in Uart read
rx2 = Uart2_Read_Char 'read and put in Buffer
X[cnt] = rx2
inc (cnt) 'Increment buffer pointer
end if
IFS1.14=0 'clear INT flag U2
if (cnt = 149)Then 'check if 150 bytes in buffer
cnt = 0
end sub
'**********************************************************
'This procedure initializes the micro
'**********************************************************
sub procedure Init()
INTCON1.15 = 1 'nested interupts disabled
IEC1.14 = 1 'Enable U2RXIE
IFS1.14 = 0 'Clear Interupt Flag U2RX
Uart2_Init(2400)
cnt = 0 ' Clear Rx Buffer pointer
end sub
'**********************************************************
'Main Code Loop
'**********************************************************
main:
Init()
while True
nop
wend
end.
'***********************************************************
if you place a break point inside the interrupt and then send the char your debugger should then stop at the break point in the interrupt indicating the interrupt is fired ,
Hope this helps you
regards
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------
Hi P.Erasmus,
I tried the code but somehow no luck. So I tried to use the ICD and when it comes to the Uart2_init(9600), I get a Warrning Message stating source file not found: _lib_uart2_p24_p33.dpas would you like to perform a step over instead?
I checked with support also on this error and they say simply ignore. Also, I am using a LV23-33A dev. board but all samples are for LV23-33, I think there is some compatibility issues since LCD / GLCD samples also dont run.
I modfied the code slightly by adding the line
uart2_write_text("o")
sub procedure rxb org $0050
if (Uart2_Data_Ready = 1) then 'if data in Uart read
rx2 = Uart2_Read_Char 'read and put in Buffer
X[cnt] = rx2
inc (cnt) 'Increment buffer pointer
end if
if (cnt = 149)Then 'check if 150 bytes in buffer
cnt = 0
end if
uart2_write_text("0")
IFS1.14=0
end sub
to enable me confirm the interrupt is working, but I get no receive data on terminal.
regards,
Nikhil
I tried the code but somehow no luck. So I tried to use the ICD and when it comes to the Uart2_init(9600), I get a Warrning Message stating source file not found: _lib_uart2_p24_p33.dpas would you like to perform a step over instead?
I checked with support also on this error and they say simply ignore. Also, I am using a LV23-33A dev. board but all samples are for LV23-33, I think there is some compatibility issues since LCD / GLCD samples also dont run.
I modfied the code slightly by adding the line
uart2_write_text("o")
sub procedure rxb org $0050
if (Uart2_Data_Ready = 1) then 'if data in Uart read
rx2 = Uart2_Read_Char 'read and put in Buffer
X[cnt] = rx2
inc (cnt) 'Increment buffer pointer
end if
if (cnt = 149)Then 'check if 150 bytes in buffer
cnt = 0
end if
uart2_write_text("0")
IFS1.14=0
end sub
to enable me confirm the interrupt is working, but I get no receive data on terminal.
regards,
Nikhil
Great Happy that you solved your problem
nikhil wrote
and at a high level
a dsPIC is no toy you will realize this as you start to understand them better ,you can run thins in parallel use a RTOS system
regards
P.E
nikhil wrote
Now you are starting to work with real embedded controllerI am actually migrating from Cubloc to Pic.
and at a high level
a dsPIC is no toy you will realize this as you start to understand them better ,you can run thins in parallel use a RTOS system
regards
P.E
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------