cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable

Hi,

   

I am sending data from android device to PSoc.By using

   

offdelayData[0] = wrReqParam->handleValPair.value.val[0];

   

offdelayData[1] = wrReqParam->handleValPair.value.val[1];
 offdelayData[2] = wrReqParam->handleValPair.value.val[2];
  offdelayData[3] = wrReqParam->handleValPair.value.val[3];
    offdelayData[4] = wrReqParam->handleValPair.value.val[4];
      offdelayData[5] = wrReqParam->handleValPair.value.val[5];

   

I get six bytes from device one by one.

   

In order to concatenate I converted each bytes to character by using

   

utoa(offdelayData[0], t0,10 );
 utoa(offdelayData[1],t1,10 );
utoa(offdelayData[2],t2,10 );
utoa(offdelayData[3],t3,10);
utoa(offdelayData[4],t4,10);
utoa(offdelayData[5],t5,10 );

   

and then concatenated to "t0"

   

strcat(t0,t1);
strcat(t0,t2);
strcat(t0,t3);
 strcat(t0,t4);
strcat(t0,t5);

   

then initialised to char *t=t0;

   

then converted to integer

   

 OffDelay=strtoul(t, &ptr1, 10);

   

While executing it is advertising but not received in Android device.

   

Please Give suggestions.

   

By Joany.

0 Likes
1 Solution
JoMe_264151
Expert II

Conversions like those are usually performed using shift left by 8 and ORing the result with the second byte resulting in a 16bit int.

   

When a 32bit result is expected use shift and ORs appropriately.

   

Your utoa() conversion requires as result an array of 4 characters: a byte can be as much as "255" and there is a trailing '\0" byte.

   

 

   

Bob

View solution in original post

0 Likes
54 Replies
Anonymous
Not applicable

I want to know about RTC_Update().It will be good if examples are provided based on RTC_Update.

   

I referred RTC_P4_WDT_Example.

   

In that example

   

"LED_WdtIsr_Write((uint8)~(LED_WdtIsr_Read()));" is used to toggle pin and they have updated RTC by using "RTC_Update();".                                    Can I give  different values for on delay and off delay of a pin?     If so what will be the format?                                                                  What is the function of RTC_Update?"
LFCLK cycle is defined as "#define LFCLK_CYCLES_PER_SECOND     (32768u)"                                                                                     Why LFCLK_CYCLES_PER_SECOND  is defined as 32768u?
Can I follow the same format for using WDT in RTC?                                                                                                                                      If yes ,how is it possible to control the number of cycles in LED blink?

   

Regards,

   

Joany.

0 Likes
JoMe_264151
Expert II

I feel that you are thinking too complicated. You have got a PSoC, so why don't you use WDT for your RTC and another timer for controlling the internal timing which can be quite asynchronous to the WDT. In that way all your program parts are running clock independent, so your LEDs may have an on-time of 748ms and be off for 259ms if you like. An RTC is not designed to give you a time-base, but to run a calendar with a 1-second resolution. RTC gives you the weekday, the month, daylight saving etc. All this is running in background triggered by an interrupt.

   

Blinking an LED can be done with a sequence of LED toggling and  CyDelay() calls (preferably in a loop) or with your own interrupt driven combination of hard- and software.

   

 

   

Bob

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi Bob,

   

I have tried by using SysTick Timer interrupt.

   

I want to know about the function of "RTC_update()" in this project.

   

What is the use of   

   

                    "CySysTickSetCallback(i, SysTickIsrHandler);"

   

         and   "RTC_SetPeriod(1u, SYSTICK_EACH_10_HZ);"?

   

Hereby I have attached the project named "TwoLEDBlink1". It works fine.

   

I want to repeat some LED process in the project.So I modified the project by using Timer counter interrupt.But the LED process didn't finish .It ended in between.Give suggestions if there is any modification  in TopDesign or in cydwr file.The modified project is named as "TwoLEDBlink2".

   

Thanks and Regards,

   

Joany.

0 Likes
JoMe_264151
Expert II

What is the use of   

   

                    "CySysTickSetCallback(i, SysTickIsrHandler);"

   

This is described in the "PSoC 4 System Reference Guide, Boot Component 5.30" which you find under Creator -> Help together with all functions regarding SysTick Timer.

   

RTC_SetPeriod() is explained in the RTC datasheet, it defines the number of ticks it takes for a second.

   

 

   

Your Timer gets stuck because you defined it as a one/shoot. That would require a reset signal to start again.

   

Your variable "flag" is changed in the interrupt handler. All global variables changed in an interrupt handler must be declared as "volatile" or you get into serious trouble when optimization for compiler is changed!

   

Wanting to learn more about LEDs? Have a look at the PrISM component (Digital->Functions) to controll brightness. Control a component's inputs by using a ControlRegister component.

   

 

   

You use

   

            //Red LED blinks for five times
              for(i=1;i<=5;i++)
               {               
                Red_Write(0u);
                CyDelay(10);
                Red_Write(1u);
                CyDelay(500);
               }

   

Why not writing a function as

   

LED_RedBlink(uint8 NumberOfTimes)...

   

This would make your main() more readable...

   

 

   

Bob

0 Likes
Anonymous
Not applicable

ok Thanks Bob.I will refer the documents and proceed further.

   

Regards,

   

Joany

0 Likes
JoMe_264151
Expert II

Some more helpful tricks: right clicking on a variable or function name opens a menu from where you can choose "go to Definition" which brings you instantly to the point of interest (ctrl - brings you back) and you can get a list of all references to that object within your code.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

ok Bob .Thanks for your valuable suggestions.I learnt how to use SysTick Timer and also I used subfunction "LED_RedBlink(uint8 NumberOfTimes)".Now I am able to control LEDs' blink independently.

   

Thanks and Regards 

   

Joany

0 Likes
Anonymous
Not applicable

Hi,

   

While executing , I want to know how to read the values of PSoc  by using UART.

   

  While executing I want to read "no_of_cycles" and "NumberOfTimes" in my project.

   

I am using putty terminal.

   

Hereby I have attached my project.

   

I have used "sprintf(no_of_time, "%d",j);" but the value of j is not displayed in the terminal.

   

Give suggestions.

   

Regards,

   

 Joany.

0 Likes
JoMe_264151
Expert II

You are not (yet) short of resources, so there is no need of using the software UART, the UART (SCB) would  not disturb any interrupt process. Set the Rx and Tx buffers to 80 and select Byte mode.

   

The USB-UART bridge of the kitprog uses dedicated (already wired) pins: RX is P1_5 and Tx is P1_4. See the Kit Guide chapter 3.7 page 35

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks Bob.It worked.

   

By Joany.

0 Likes
Anonymous
Not applicable

Hi,

   

I want to execute two LEDs simultaneously.But it executes sequentially.

   

Here I have attached my project.

   

Give suggestions.

   

Best Joany.

0 Likes
JoMe_264151
Expert II

You are using for-loops and CyDelay() function which when executed bind all the CPU power. What you need is an automatism that blinks the LED and returns immediately to the calling program using only few CPU resources.

   

This can only be done with an interrupt (hardware, component) and an interrupt handler (software).

   

Try the following:

   

Start with a PWM and configure it for the correct permanent blinking.

   

Write a routine Blink_WDT_LED() that sets up the PWM and starts it.

   

Add an isr component connected to terminal count, use StartEx(Handler)

   

In Handler, count the number of TCs, when 5, stop the PWM

   

Do the same for the second LED.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi Bob ,

   

Thank you for your valuable suggestions.I will try it.I want to know the difference between WDT and TCPWM?

   

Thanks and regards,

   

Joany.

0 Likes
Anonymous
Not applicable

Hi Bob,

   

I learnt the difference between WDT and TCPWM.

   

I want to know the calculation behind SAFlash.When I give input "1600010".It displays "10 106 24 0"(arr[0] ->10,arr[1] ->106,

   

arr[2]->24,arr[3]->0).

   

Regards ,

   

Joany.

0 Likes
Anonymous
Not applicable

Hi Bob,

   

I learnt the difference between WDT and TCPWM.

   

I want to know the calculation behind SFlash.When I give input "1600010".It displays "10 106 24 0"(arr[0] ->10,arr[1] ->106,

   

arr[2]->24,arr[3]->0).

   

Regards ,

   

Joany.

0 Likes