- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everybody.
Please advise me an my trouble.
I try to send a letter through UART.
This program work on ISR interrupt routine by 50Hz.
I could receive a serial data only 4 words which is "ABCD".
Why can not receive all sentences?
CY_ISR(ctrl_loop) { //50Hz
:
:
UART_1_PutString("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n\r");
CyDelay(1);
}
void main(){
HardwareReset();
CYGlobalIntEnable; // Enable Global Interrupts
isr_1_StartEx(ctrl_loop);
for(;;){
}
PC terminal show only "ABCD"
115200 bps
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Actually using a timer for 50Hz event may not be efficient.
As you might know, Cortex-M has a timer called "SysTick" which can be used without consuming other resource(s).
So following is another sample using "SysTick".
schematic
Note: This time we don't need a counter nor clock and interrupt.
pins
main.c
==================
#include "project.h"
#include "stdio.h"
#define STR_LEN 64
char str[STR_LEN+1] ;
void print(char *str)
{
// UART_UartPutString(str) ; /* PSoC 4 */
UART_1_PutString(str) ; /* PSoC 5 */
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(20) ;
print("\033[2J") ; /* clear screen */
CyDelay(20) ;
}
void splash(char *prog_name)
{
cls() ;
if (prog_name && *prog_name) {
print(prog_name) ;
}
print(" (") ;
print(__DATE__) ;
print(" ") ;
print(__TIME__) ;
print(")\n") ;
}
volatile int timer_flag = 0 ;
volatile uint32_t tick_count = 0 ;
CY_ISR(tick_callback)
{
tick_count++ ;
if ((tick_count % 20) == 0) {
timer_flag = 1 ; /* 50Hz hit! */
}
}
int find_empty_slot(void)
{
int result = -1 ;
uint32_t i ;
for (i = 0 ; i < CY_SYS_SYST_NUM_OF_CALLBACKS ; i++ ) {
if (CySysTickGetCallback(i) == NULL) {
result = i ;
break ;
}
}
return(result) ;
}
int main(void)
{
int sys_tick_slot = 0 ;
CyGlobalIntEnable; /* Enable global interrupts. */
UART_1_Start() ;
splash("5LP 50Hz Timer Test D") ;
sys_tick_slot = find_empty_slot() ;
if (sys_tick_slot < 0) {
print("Sorry No empty SysTick Slot available\n\r") ;
while(1) { } /* halting here */
} else {
snprintf(str, STR_LEN, "Starting Tick at slot %d\n\r", sys_tick_slot) ;
print(str) ;
CySysTickStart() ;
CySysTickSetCallback(sys_tick_slot, tick_callback) ;
}
for(;;)
{
if (timer_flag) {
timer_flag = 0 ;
UART_1_PutString("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n\r");
CyDelay(1) ;
}
}
}
==================
Tera Term log
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
In general an ISR must be returned as soon as possible
to avoid disturbing other activities in the program and/or the MCU.
And because of its nature, usually a function which allocates memory
or takes very long time is not supposed to be in an ISR.
Having said that, when I modified your ISR to
=================
CY_ISR(timer_isr)
{
Timer_1_ReadStatusRegister() ;
UART_1_PutString("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n\r");
CyDelay(10) ;
}
=================
It worked.
But to prevent troubles in the future, I would recommend to write a program something like
======================
volatile int timer_flag = 0 ;
CY_ISR(timer_isr)
{
Timer_1_ReadStatusRegister() ;
timer_flag = 1 ;
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_1_Start() ;
splash("5LP 50Hz Timer Test A") ;
isr_1_StartEx(timer_isr) ;
Timer_1_Start() ;
for(;;)
{
if (timer_flag) {
timer_flag = 0 ;
UART_1_PutString("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n\r");
CyDelay(1) ;
}
}
}
======================
Result Tera Term log
Attached are my samples using CY8CKIT-059
uart_50Hz_200505A: recommended
uart_50Hz_200505B: worked, but not recommended.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Moto san
Thank you very much for so quick response.
I understood it, but I did not use timer block in order to make interrupt signal.
May be should I use timer block?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Actually using a timer for 50Hz event may not be efficient.
As you might know, Cortex-M has a timer called "SysTick" which can be used without consuming other resource(s).
So following is another sample using "SysTick".
schematic
Note: This time we don't need a counter nor clock and interrupt.
pins
main.c
==================
#include "project.h"
#include "stdio.h"
#define STR_LEN 64
char str[STR_LEN+1] ;
void print(char *str)
{
// UART_UartPutString(str) ; /* PSoC 4 */
UART_1_PutString(str) ; /* PSoC 5 */
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(20) ;
print("\033[2J") ; /* clear screen */
CyDelay(20) ;
}
void splash(char *prog_name)
{
cls() ;
if (prog_name && *prog_name) {
print(prog_name) ;
}
print(" (") ;
print(__DATE__) ;
print(" ") ;
print(__TIME__) ;
print(")\n") ;
}
volatile int timer_flag = 0 ;
volatile uint32_t tick_count = 0 ;
CY_ISR(tick_callback)
{
tick_count++ ;
if ((tick_count % 20) == 0) {
timer_flag = 1 ; /* 50Hz hit! */
}
}
int find_empty_slot(void)
{
int result = -1 ;
uint32_t i ;
for (i = 0 ; i < CY_SYS_SYST_NUM_OF_CALLBACKS ; i++ ) {
if (CySysTickGetCallback(i) == NULL) {
result = i ;
break ;
}
}
return(result) ;
}
int main(void)
{
int sys_tick_slot = 0 ;
CyGlobalIntEnable; /* Enable global interrupts. */
UART_1_Start() ;
splash("5LP 50Hz Timer Test D") ;
sys_tick_slot = find_empty_slot() ;
if (sys_tick_slot < 0) {
print("Sorry No empty SysTick Slot available\n\r") ;
while(1) { } /* halting here */
} else {
snprintf(str, STR_LEN, "Starting Tick at slot %d\n\r", sys_tick_slot) ;
print(str) ;
CySysTickStart() ;
CySysTickSetCallback(sys_tick_slot, tick_callback) ;
}
for(;;)
{
if (timer_flag) {
timer_flag = 0 ;
UART_1_PutString("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n\r");
CyDelay(1) ;
}
}
}
==================
Tera Term log
moto