PSoC™ 4 Forum Discussions
Hello folks,
I've a question regarding I2C communication in CY8CKIT-042 pioneer board.
What I want to do is a simple I2C communication; Write a byte and read a value from slave. It could be programmed in Arduino like below.
#include <Wire.h>
const int address = 0x40;
void setup()
{
// open the serial port
Serial.begin(57600);
// Start the I2C module
Wire.begin();
}
void loop()
{
// start a transmission to the slave
Wire.beginTransmission(address);
// request register 0
Wire.write((byte)0);
// issue the request
Wire.endTransmission();
// prepare to receive on byte
Wire.requestFrom(address, 1);
// wait for the data to be ready
while(!Wire.available());
// print the temperature
Serial.println(Wire.read(),DEC);
delay(1000);
}
I started this program with an example project, I2cCommMaster. When I try this project with my commands and slave address, I found that the master couldn't complete write, so my program holds here;
[main.c @ line:85]
while (0u == (I2CM_I2CMasterStatus() & I2CM_I2C_MSTAT_WR_CMPLT))
{
/* Waits until master completes write transfer */
}
Could you guys help me to make this code run? I attach all my code below for your information.
Thanks for your help in advance.
- <main. c >
-
- /*******************************************************************************
- * File Name: main.c
- *
- ********************************************************************************
- * Copyright 2014, 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 "project.h"
- #include "header.h"
-
-
- /*******************************************************************************
- * Function Name: main
- ********************************************************************************
- * Summary:
- * The main function performs the following actions:
- * 1. Turns off the RGB LED.
- * 2. Starts the I2C master (SCB mode) component.
- * 3. Enables global interrupts.
- * 4. Sends command and status packets to the slave every 500mS.
- *
- * Parameters:
- * None
- *
- * Return:
- * None
- *
- *******************************************************************************/
- void main ( )
- {
- uint8 command = CMD_MSR_REL_HUM_NO_HOLD_MASTER ;
-
- RGB_LED_OFF ;
-
- I2CM_Start ( ) ;
-
-
- CyGlobalIntEnable ;
-
- /***************************************************************************
- * Main polling loop
- ***************************************************************************/
- for ( ;; )
- {
-
- if (0u == WriteCommandPacket (command ) )
- {
-
- if (0u == ReadStatusPacket ( ) )
- {
- RGB_LED_OFF ; /* Turn off status LED */
- }
- }
-
- CyDelay (500u ) ; /* Send command to the I2C slave every 500mS */
- }
- }
-
-
- /*******************************************************************************
- * WriteCommandPacket(): Writes command packet to I2C slave
- *******************************************************************************/
- uint32 WriteCommandPacket ( uint8 cmd )
- {
- uint8 buffer [BUFFER_SIZE ] ;
- uint32 status = TRANSFER_ERROR ;
-
- /* Initialize buffer with packet */
- buffer [PACKET_SOP_POS ] = PACKET_SOP ;
- buffer [PACKET_CMD_POS ] = cmd ;
- buffer [PACKET_EOP_POS ] = PACKET_EOP ;
-
- ( void ) I2CM_I2CMasterWriteBuf (I2C_SLAVE_ADDR , buffer , PACKET_SIZE , I2CM_I2C_MODE_COMPLETE_XFER ) ;
- //I2CM_I2CMasterReadBuf(I2C_SLAVE_ADDR, buffer, PACKET_SIZE, I2CM_I2C_MODE_COMPLETE_XFER);
- RGB_LED_ON_RED ;
- while (0u == (I2CM_I2CMasterStatus ( ) & I2CM_I2C_MSTAT_WR_CMPLT ) )
- {
- /* Waits until master completes write transfer */
- }
- RGB_LED_ON_GREEN ;
-
- /* Displays transfer status */
- if (0u == (I2CM_I2C_MSTAT_ERR_XFER & I2CM_I2CMasterStatus ( ) ) )
- {
- RGB_LED_ON_GREEN ;
-
- /* Check if all bytes was written */
- if (I2CM_I2CMasterGetWriteBufSize ( ) == BUFFER_SIZE )
- {
- status = TRANSFER_CMPLT ;
- }
- }
- else
- {
- RGB_LED_ON_RED ;
- }
-
- ( void ) I2CM_I2CMasterClearStatus ( ) ;
-
- return (status ) ;
- }
-
-
- /*******************************************************************************
- * ReadStatusPacket(): Reads status packet from I2C slave
- *******************************************************************************/
- uint32 ReadStatusPacket ( void )
- {
- uint8 buffer [BUFFER_SIZE ] ;
- uint32 status = TRANSFER_ERROR ;
-
- ( void ) I2CM_I2CMasterReadBuf (I2C_SLAVE_ADDR , buffer , PACKET_SIZE , I2CM_I2C_MODE_COMPLETE_XFER ) ;
-
- while (0u == (I2CM_I2CMasterStatus ( ) & I2CM_I2C_MSTAT_RD_CMPLT ) )
- {
- /* Waits until master complete read transfer */
- }
-
- /* Displays transfer status */
- if (0u == (I2CM_I2C_MSTAT_ERR_XFER & I2CM_I2CMasterStatus ( ) ) )
- {
- RGB_LED_ON_GREEN ;
-
- /* Check packet structure */
- if ( (I2CM_I2CMasterGetReadBufSize ( ) == BUFFER_SIZE ) &&
- (PACKET_SOP == buffer [PACKET_SOP_POS ] ) &&
- (PACKET_EOP == buffer [PACKET_EOP_POS ] ) )
- {
- /* Check packet status */
- if (STS_CMD_DONE == buffer [PACKET_STS_POS ] )
- {
- status = TRANSFER_CMPLT ;
- }
- }
- }
- else
- {
- RGB_LED_ON_RED ;
- status = TRANSFER_ERROR ;
- }
-
- ( void ) I2CM_I2CMasterClearStatus ( ) ;
-
- return (status ) ;
- }
-
-
- /* [] END OF FILE */
-
-
-
-
-
-
-
- <header. h >
- /*******************************************************************************
- * File Name: header.h
- *
- ********************************************************************************
- * Copyright 2014, 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 <project.h>
-
- /***************************************
- * Function Prototypes
- ****************************************/
-
- /* Function prototypes */
- uint32 CheckSwitchState ( void ) ;
- uint32 WriteCommandPacket ( uint8 cmd ) ;
- uint32 ReadStatusPacket ( void ) ;
-
-
- /***************************************
- * Constants
- ****************************************/
-
- /* I2C slave address to communicate with */
- #define I2C_SLAVE_ADDR (0x40u) //(0x48u)//
-
- /* Buffer and packet size */
- #define BUFFER_SIZE (3u)
- #define PACKET_SIZE (BUFFER_SIZE)
-
- /* Packet positions */
- #define PACKET_SOP_POS (0u)
- #define PACKET_CMD_POS (1u)
- #define PACKET_STS_POS (PACKET_CMD_POS)
- #define PACKET_EOP_POS (2u)
-
- /* Start and end of packet markers */
- #define PACKET_SOP (0x01u)
- #define PACKET_EOP (0x17u)
-
- /* Command valid status */
- #define STS_CMD_DONE (0x00u)
- #define STS_CMD_FAIL (0xFFu)
-
- /* Command valid status */
- #define TRANSFER_CMPLT (0x00u)
- #define TRANSFER_ERROR (0xFFu)
-
- /* Commands set */
- //#define CMD_SET_OFF (0u)
- //#define CMD_SET_RED (1u)
- //#define CMD_SET_GREEN (2u)
- //#define CMD_SET_BLUE (3u)
- #define CMD_MSR_REL_HUM_HOLD_MASTER (0xE5u)
- #define CMD_MSR_REL_HUM_NO_HOLD_MASTER (0xF5u)
- #define CMD_MSR_TEMP_HOLD_MASTER (0xE3u)
- #define CMD_MSR_TEMP_NO_HOLD_MASTER (0xF3u)
- #define CMD_RESET (0xFEu)
-
-
- /***************************************
- * Macros
- ****************************************/
-
- /* Set LED RED color */
- #define RGB_LED_ON_RED \
- do{ \
- LED_RED_Write (0u); \
- LED_GREEN_Write(1u); \
- }while(0)
-
- /* Set LED GREEN color */
- #define RGB_LED_ON_GREEN \
- do{ \
- LED_RED_Write (1u); \
- LED_GREEN_Write(0u); \
- }while(0)
-
- /* Set LED BLUE color */
- #define RGB_LED_ON_BLUE \
- do{ \
- LED_RED_Write (1u); \
- LED_GREEN_Write(1u); \
- }while(0)
-
- /* Set LED TURN OFF */
- #define RGB_LED_OFF \
- do{ \
- LED_RED_Write (1u); \
- LED_GREEN_Write(1u); \
- }while(0)
-
-
- /* [] END OF FILE */
Hello,
I have been using the CY8CKIT-042 PSoC 4 Pioneer Kit board with PSoC Creator for some time with no problems until yesterday.
But now for unknown reason I get a Port Aquire Error.
First, during Build I get a Warning:
Warning in component: cy_boot. CY_BOOT: Function: CySysFlashWriteRow() fails to write a row of flash memory if the data to be written has a zero in the lower 32-bits of the checksum. See KBA94530 (http://www.cypress.com/go/KBA94530) for the details.
This might have been present earlier, and might be totally irrelevant. Otherwise Build is OK.
When I attempt to Program, the "Select Debug Target" panel opens (this did not happen earlier -- it always just programmed straight away.)
The panel offers only one target: KitProg/0D1A140900163400. This seems to be OK. But when I click the Port Aquire button the error message pops up, with details as follows:
There was an error attempting to run the port acquire command. This is often a result of no supported devices being attached, or a device being used by another application. Ensure that everything is properly connected, and that no other application is using the device and try again.
And programming does not take place.
The green Status LED on the board is lit and steady.
Windows Device Manager reports the three drivers associated with PSoC as all working properly.
Finally, I also have a CY8CKIT-049 PSoC 4 Prototyping Board, and this can be programmed via Bootloader Host using same USB port with no problem.
So I am stuck -- Can anyone help? Many thanks, and Happy Christmas, Ken.
[ Note: I will be away from my PC from later today 'til 29 Dec, so might not be able to respond quickly, but thought I'd get the post rolling anyway. ]
Show LessHi,
I am working on CYRF6936 transceiver module interfaced with PSoC 4 prototyping kit. I think it is one of SPI based "CYFI" radio modules housed on Artaflex AWP24S modules.
I am just 2 months old to PSoC world. I am trying to establish a basic one- way communication between two such modules with one module acting as a transmitter and the other as a receiver.
I recently raised a support ticket in MyCases in this same website asking for code to achieve the same. They instead provided me with Star Network Protocol (CYFISNP) code with HUB and NODE modules.
Prob#1:
I went through the documentation but I'm not able to understand the exact sequence of operation of the hub and nodes. Also I'm not able to establish the desired simplex communication using the same API functions that the SNP code uses, since the "core" of the code is dissolved inconspicuously within the complexity of the protocol itself. Basically the basic radio operation is severely coupled with the protocol operation making it difficult for beginners to test the working of the CYFI radio module.
Prob#2:
There is a sample code in the CYFISPI datasheets but it is for M8C architecture.
Prob#3:
Also the connector on the CYFI module is not compatible with standard connector buses, which requires us to use a connector "bridge" to connect to PSoC. The exact part number of the bridge is PDC-9370. Unfortunately there is no datasheet available for this connector and hence I'm not able to figure out the exact pins to connect to PSoC.
Prob#4:
CYRF6936-40LFXC is obsolete and it is replaced by CYRF6936-40LTXC. The radio drivers availabe are for CYRF7936 and PRoC. I am not sure if they are compatible with my part number. If they are not then I'm not able to get the correct datasheet.
Nevertheless I have managed to put a few lines of code and the "guessed" connections together but the transmitter is stuck in TX mode and receiver is stuck in RX mode. I am using character LCD for display and debug.
I have attached a few snaps of the setup and the code itself. I would be very grateful if someone can go through the code and help me get the radios talking to each other.
Thanks and regards,
Shreesha
Show LessPlease chech the question posted here:
http://www.cypress.com/?app=forum&id=4749&rID=103823&start=1&message=posted
Many thanks!
Show LessDoes anybody know free middleware for the PSOC4 (ARM Cortex M0) with file system support (Flash RAM, SdCard) ?
I know there is a very good middleware for the ARM Keil professional suite but I look for open source or free software.
Dear friends,i would like to implement project requirind displaying information on tft screen such as running counter,environment conditions ,and etd.
The platform i use is PSOC4 pioneer kit.
If someone has experience or code for driving TFT (2.2-3.5 inch) or other type of display of such size,I would more than happy if you can share with me your thougts or any useful information regarding the thread.
Alex.
Show LessHello!
Recently a friend and I both purchased the psoc 4 ble trainer and have been enjoying tinkering around together with the example projects, including the element14 100 projects of psoc4 (to some success and a lot of failure, which is just as much fun). I also heard that a new 100 ble projects was coming soon. Very excited to see this!
What I came to ask, or am in search of is a way that both of us could link our trainers together. Nothing fancy, we've just been talking a lot about trying to figure it out, and we are in no way anything more than pure novices. Something that could allow one of us to turn on the led of the others trainer with the push of a button or something simple. Would anyone here have information that could help us with this experiment or could direct us to some great, easy to understand knowledge so that we may figure out how to accomplish something like this?
Any and all help will be greatly appreciated! Thank you for your time.
Show LessSo I got the New BLE 042 Kit... great kit got it working fast! Heres my problem i am very new to bluetooth and i have gone through many example projects trying to dissect them and see how they work. After days of work i know how they all fit together and how each file intertwines, but honestly as a noob to even PSOC i find my self struggling to get the whole picture. My previous experiences have been with Arduino which has tons of people making tutorial videos....i really would like to move on to PSOC and i have fallen in love with the system already. My main question is.... how do i learn? What resources can i tap into that can give me clear instruction?I simply want to learn a basic way to get my board to talk to my dongle. Then i can move on to intergrating more complex logic. I have done an immense amount of search but cannot find any resources that have really helped alot... most of it assumes you are an expert in the subject . any help would be greatly apreaciated.
-Thanks
Show LessIn my current PSoC 4200BLE project the enabling of an isr seems to "block" the rest of the main function.
In main there is a for loop after the ISR is enabled where I want to "print" to the UART some data calculated in the ISR, but the system naver reaches that part of the code:
CyGlobalIntEnable;
isr1_Disable();
isr1_SetVector(InterruptHandler1);
isr1_Enable();
for(;;)
{
UART_UartPutString("in main \n");
}
If I don't enable the ISR, the message in the for loop is sent. But if I do enable the ISR, it is not.
Show Less