PSoC™ 5, 3 & 1 Forum Discussions
Hello,
I made a simple app to play with interrupt handling. In loop it increments a counter and it's value is sent to UART.
When a byte is received on UART an ISR is called and the counter should be reset. By some reason the app works until a byte is received and than it hangs. The app hangs even if ISR has no code at all. Here is my code:
main.c:
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include <stdio.h>
#pragma interrupt_handler uartIsrRx;
unsigned char counter;
void main(void)
{
unsigned int i;
unsigned char str[16];
M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
UART_Start(UART_PARITY_NONE);
UART_IntCntl(UART_ENABLE_RX_INT);
while (1)
{
counter++;
csprintf(str, "c=%d\r\n", (int)counter);
UART_PutString(str);
for (i=0; i!=20000; i++);
}
}
void uartIsrRx(void )
{
counter=0;
}
UARTINT.asm:
_UART_RX_ISR:
...
...
;---------------------------------------------------
; Insert a lcall to a C function below this banner
; and un-comment the lines between these banners
;---------------------------------------------------
PRESERVE_CPU_CONTEXT
lcall _uartIsrRx
RESTORE_CPU_CONTEXT
reti
Attachment:
UART and PSoC global settings.
Best Regards
Show LessI am trying to interfacing I2C between two PSOC3. I have written the following code
for MASTER
/*****************************
* File Name: main.c
*
* Version: 1.0
*
* Description:
* This is source code for Example Project: 8-ch DelSig ADC with I2C Master.
*
* Parameters used:
* I2C Master
* Implementation Fixed function
* Data rate 100kbps
* SDA SCL pin config Open drain, drives low
* Pull-up resistors 2.67k each
*
* Delta Sigma ADC
* Conversion mode 1-Multi Sample
* Resolution 16 bits
* Conversion Rate 5000 SPS
* Input mode Differential
*
* IDAC
* Polarity Positive
* Range 0-31.875 uA
* Speed Slow
* Current output 10 uA
*
* Sequencing Max
* Mux type Differential
* Channels 8
*
* In this project, data converted by the 8-channel, sequenced ADC is sent via
* a I2C Master. The project is tested with a separate project containing a I2C
* slave. The data output by the ADC is made visible on an Character LCD. This
* can be used to verify the data received by the I2C slave which is also
* displayed on an LCD screen.
*
******************************
* Copyright 2012, Cypress Semiconductor Corporation. All rights reserved.
* This software is owned by Cypress Semiconductor Corporation and is protected
* by and subject to worldwide patent and copyright laws and treaties.
* Therefore, you may use this software only as provided in the license agreement
* accompanying the software package from which you obtained this software.
* CYPRESS AND ITS SUPPLIERS MAKE NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* WITH REGARD TO THIS SOFTWARE, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT,
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
******************************
#include <device.h>
/* The I2C Slave address by default in a PSoC device is 8 */
#define I2C_SLAVE_ADDRESS (8u)
/* Set the write buffer length to be 16 bits or 2 bytes */
#define WR_BUFFER_SIZE (5u)
/*****************************
* Function Name: main
******************************
*
* Summary:
* main function performs following functions:
* 1. Starts all used components.
* 2. Controls sequencing of ADC inputs.
* 3. Reads ADC converted data, sends this data via a I2C Master.
* 4. Displays ADC converted data on Character LCD.
*
* Parameters:
* None.
*
* Return:
* None.
*
******************************
int main()
{
uint8 i;
uint8 temp;
uint8 sample_segment[WR_BUFFER_SIZE]
for (i = 0; i < WR_BUFFER_SIZE; i++)
{
sample_segment = i;
}
LCD_Char_Start();
LCD_Char_PrintString("Start1")
I2CM_Start();
/* The Start API for Mux sets it up, but disconnects all the channels.
* To connect the first channel, call the 'AMuxSeq_Next' function.
*/
/* The LCD will display the values read from ADC in hex */
/* Enable global interrupts - required for I2C */
CyGlobalIntEnable;
//for(;;)
// {
/* Attempt to initiate communication with the slave until the function
* completes without error.
*/
do
{
/* The syntax below automatically writes a buffer of data to a slave
* device from start to stop.
*/
temp = I2CM_MasterWriteBuf(I2C_SLAVE_
}
while (temp != I2CM_MSTR_NO_ERROR);
LCD_Char_ClearDisplay();
LCD_Char_PrintString("Stop1! ");//debugging
/* Wait for the data transfer to complete */
while(I2CM_MasterStatus() & I2CM_MSTAT_XFER_INP);
LCD_Char_PrintString("Stop2! ");//debugging
temp = I2CM_MasterClearStatus();
LCD_Char_ClearDisplay();
/* If there is an error while transferring data */
if(temp & I2CM_MSTAT_ERR_XFER)
{
/* Indicate the error */
LCD_Char_PrintString("I2C Error! ");
/* Place error handling code here */
}
else /* Write completed without error */
{
/* For verification purposes, display the adcReading on the LCD */
LCD_Char_PrintString("Transfer complete");
CyDelay(1000u/*ms*/);
LCD_Char_ClearDisplay();
for (i = 0; i < WR_BUFFER_SIZE; i++)
{
LCD_Char_PrintInt8(sample_
}
}
/* Delay introduced for ease of reading LCD */
CyDelay(10000u/*ms*/);
} /* End forever loop */
//} /* End main */
/* [] END OF FILE */
//and for SLAVE
/*****************************
* File Name: main.c
*
* Version: 1.0
*
* Description:
* This is source code for the 8-ch DelSig ADC and I2C Slave Example Project.
*
* Parameters used:
* I2C Slave
* Implementation Fixed function
* Data rate 100kbps
* SDA SCL config Open drain, drives low
* Pull-up resistors 2.67k each
* Address 8
* Address decode Hardware
*
* Delta Sigma ADC
* Conversion mode 1-Multi Sample
* Resolution 16 bits
* Conversion Rate 5000 SPS
* Input mode Differential
*
* IDAC
* Polarity Positive
* Range 0-31.875 uA
* Speed Slow
* Output Current 10uA
*
* Sequencing Max
* Mux type Differential
* Channels 8
*
* In this project, data converted by the 8-channel, sequenced ADC is sent via
* I2C. The main project containing an I2C slave is tested with a separate
* project containing an I2C master. The data output by the ADC is made
* visible on an Character LCD. This can be used to verify the data
* received by the I2C master which is also displayed on an LCD screen.
*
* The communication flow is as follows:
* When the device is reset, all components are started and an initial ADC
* reading is taken. This is stored in the read buffer of the I2C slave and
* the ADC is stopped. Then the infinite 'for' loop begins. Only if the correct
* number of bytes of the read buffer are read by the I2C master, a new reading
* is taken from the ADC and the loop continues.
*
******************************
* Copyright 2012, Cypress Semiconductor Corporation. All rights reserved.
* This software is owned by Cypress Semiconductor Corporation and is protected
* by and subject to worldwide patent and copyright laws and treaties.
* Therefore, you may use this software only as provided in the license agreement
* accompanying the software package from which you obtained this software.
* CYPRESS AND ITS SUPPLIERS MAKE NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* WITH REGARD TO THIS SOFTWARE, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT,
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
******************************
#include <device.h>
/* Set the write buffer length to be 16 bites or 2 bytes */
#define RD_BUFFER_SIZE (10u)
uint8 wrBuf[RD_BUFFER_SIZE];
uint8 userArray[RD_BUFFER_SIZE];
uint8 byteCnt;
uint8 i;
/*****************************
* Function Name: main
******************************
*
* Summary:
* main function performs following functions:
* 1. Starts all used components.
* 2. Controls sequencing of ADC inputs.
* 3. Reads ADC converted data, puts this in a read buffer to be read by the
* I2C Master.
* 4. Displays ADC converted data on Character LCD.
*
* Parameters:
* None.
*
* Return:
* None.
*
******************************
int main()
{
/* To conserve memory space, set up temporary variable for storing ADC
* converted values and the write buffer as a union.
*/
LCD_Char_Start();
LCD_Char_PrintString("Slave Start! ");
/* Initialize write buffer before call I2C_Start */
I2CS_SlaveInitWriteBuf((uint8 *) wrBuf, RD_BUFFER_SIZE);
/* Start I2C Slave operation */
I2CS_Start();
CyGlobalIntEnable;
/* Wait for I2C master to complete a write */
for(;;) /* loop forever
*/
{
/* Wait for I2C master to complete a write */
if(0u != (I2CS_SlaveStatus() & I2CS_SSTAT_WR_CMPLT))
{
byteCnt = I2CS_SlaveGetWriteBufSize();
I2CS_SlaveClearWriteStatus();
for(i=0; i < byteCnt; i++)
{
userArray = wrBuf; /* Transfer data */
}
LCD_Char_PrintString("
I2CS_SlaveClearWriteBuf();
}
}
} /* End of main */
/* [] END OF FILE */
Hi Guys,
I am having some trouble with the SPI. I have looked through the site and found some documents but not a worked example.
The code is ported across from a Microchip project. The Devie is PSOC 5LP and the memory is FM25W256-G.
The code runs until the second line in the ReadByte routine and appears to hang. I have the SPI component set to Mode 0 and 4MHz using internal clock source. Does my code below look correct? Or is there something I need to enable or initialise? Thanks in advance for your help.
#define WREN 0x06
#define MEMWRITE 0x02
#define MEMREAD 0x03
unsigned char Muted;
unsigned char testbyte;
void SendByte(unsigned short MemAddress, unsigned char MemData) //FM25W256-G Device
{
MEM_EN_Write(false); //Enable Write function
SPI_WriteByte(WREN);
MEM_EN_Write(true);
MEM_EN_Write(false); //Send Write command
SPI_WriteByte(MEMWRITE);
SPI_WriteByte(MemAddress >> 8); //Send 16-bit Address, MSB first
SPI_WriteByte(MemAddress);
SPI_WriteByte(MemData); //Send Data byte
MEM_EN_Write(true);
}
unsigned char ReadByte(unsigned short MemAddress)
{
unsigned char i;
MEM_EN_Write(false); //Send Read Command
SPI_WriteByte(MEMREAD); //************************ LOCKS UP on this line ********************
SPI_WriteByte(MemAddress >> 8); //Read Address, MSB fist
SPI_WriteByte(MemAddress);
i = SPI_ReadByte(); //Read the byte ????
MEM_EN_Write(true);
return i;
}
void init(void)
{
CyGlobalIntEnable;
PWM_Start();
SPI_Init();
}
int main()
{
init();
SendByte(0x01, 0x33);
testbyte = ReadByte(0x01); //Test byte should = 0x33
for(;;) {}
Show LessIve been using the auto generated ISR's and am trying to use the Custom ISR's using the CY_ISR_PROTO() approach.
The compiler keeps telling me that " isr_1_StartEx(whatever)" is a undeclared identifier "whatever"
Any Ideas? Im sure it is something simple......
Show LessHi
Through some option exploring, I attempted the use of both the PSOC's internal and TI serial based ADS7818 converters. I started messing with the Sigma Delta converter and concluded its noise immunity suits my application best.
Therfore, I can sample at a lower rate, average less, and use less memory when transmitting samples over UARTs.
The one drawback is the PSOC 5 only has 1 Sigma Delta converter, and I need to monitor two shunts. There is a sequencing SAR converter, but no sequencing Sigma Delta. An app note I found suggested using the analog mux.
The attached project shows how I implemented it. I am receiving an asynchronus path warning. I am thinking using a clock to control the select object is not the best idea? Prior to every edge of the ACLK, the mux alternates between channels 0 and 1. The DMA thus stores every other sample as one shunt's reading, and the other offset, the other shunt. Is there a better way of sequencing? Despite the warning, the system appears to be working, but I may be paying some kind of noise penalty.
Show LessI am a beginner with PSoC, I know PSoC 4 with Create 2.2 a little, because I learn some courses on the topics some weeks ago.
Nevertheless, it seems that I must work with PSoC Designer.......If this possible?
I can find chip CYRF89235I, when I open PSoC Designer5.4, and click New Project........
Furthermore,how can I deal with CYRF89435? Which can not find the chip in PSoC Designer 5.4.
Thank you, all.
Show LessHi folks,
I'm new to PSoC, but it looks like it might be good for my design, largely by saving a bunch of grief on routing a very small board.
My question is about the best practice for duplicating functionality that I already have: The current design uses a dsPIC, which has 4x PWM generators, with 2 pins per. The pins can be selected to be digital GPIO, or PWM output, or inverted PWM output.
I'm driving a TI DRV8833 chip, which has 2 inputs, which are connected to the 2 PWM outputs. For each direction, one of the pins is enabled, while the other is left as a digital GPIO. Switching directions then just switches which one of those output pins is enabled. Then the GPIO sets the coast/brake mode of the motor.
How should I go about mimicking this funcionality the PSoC 5? For each PWM channel, should I use a single PWM block with the pwm1 and pwm2 routed directly to output pins, and then just setting the cmp1 and cmp2 values will effectively determine which output is acting like a constant high/low GPIO, and which is PWMing?
The other wrinkle is that we are doing speed sending with a PWM holdoff (95% of the counter period), where the 95% count mark triggers the ADc conversion (differential, across motor). It looks like replicating this functionality means that I'd use one of the cmp1/cmp2 values to set this event at 0.95*period, and then use one of the pwm1/pwm2 outputs to trigger start-of-conversion on the ADC. But if I do that, then I need to figure out the output switching. Just build the output logic with 2 mux's and some logic gates?
Of course, if I could get this worked out into a whole submodule that has just a duty cycle value register, a direction bit, and a coast/brake bit, that would be super.
Any advice on this would be appreciated. We chose the previous part originally because it was a "motor control" variant, which made the described application quite straightforward.
Thanks,
Andrew